blog tag

MVC RSS Feed

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

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
merlijn (12/17/2013)

Can I see the SyndiactionItem class please?


Allan Chadwick (12/22/2013)

http://msdn.microsoft.com/en-us/library/system.servicemodel.syndication.syndicationitem%28v=vs.110%29.aspx ... It is part of .net.


© Chadwick 2021