MVC RSS Feed


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...

        [HttpGet]
        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("http://www.google.com")));//Nothing alternate about it. It is the MAIN link for the item.
                items.Add(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
Comment:
Can I see the SyndiactionItem class please?


Name: Allan Chadwick
Comment Date: 12/22/2013
Comment:
http://msdn.microsoft.com/en-us/library/system.servicemodel.syndication.syndicationitem%28v=vs.110%29.aspx ... It is part of .net.


Leave a Comment:




    Captcha Challenge