Keywords: RSS, RSS Feed, MVC, C#
Publish Date: 12/30/2012
Description: Quick and easy Rss Feed in MVC

I needed to create an RSS feed last week and I ran across a video of Scott Hanselman using some built in functionality in .net. Here is the code...

And the Controller Method...

        public ActionResult RssFeed()
            var items = new List<SyndicationItem>();
            for (int i = 0; i < 20; i++)
                var item = new SyndicationItem()
                    Id = Guid.NewGuid().ToString(),
                    Title = SyndicationContent.CreatePlaintextContent(String.Format("My Title {0}", Guid.NewGuid())),
                    Content = SyndicationContent.CreateHtmlContent("Content The stuff."),
                    PublishDate = DateTime.Now
                item.Links.Add(SyndicationLink.CreateAlternateLink(new Uri("")));//Nothing alternate about it. It is the MAIN link for the item.

            return new RssFeed(title: "Greatness",
                               items: items,
                               contentType: "application/rss+xml",
                               description: String.Format("Sooper Dooper {0}", Guid.NewGuid()));


Comments (2):

Name: merlijn
Comment Date: 12/17/2013
Can I see the SyndiactionItem class please?

Name: Allan Chadwick
Comment Date: 12/22/2013
Comment: ... It is part of .net.

Leave a Comment:

    Captcha Challenge