Create RSS Feed With ASP.NET Framework 4.0


You can use the name space System.ServiceModel.Syndication in assembly System.ServiceModel which is added by default to new ASP.NET website project based on .net framework 4.0 ( I didn’t try it with .net framework 3.5 ).

Following is the code to view RSS to one channel called MyFeed and has items Hello1, Hello2 and Hello 3

1 – Create new aspx page

2 – Add the following code to its code behind in the page load handler

//Prepare the channel
Uri uri = new Uri(“http://helloworld”);
List<SyndicationItem> items = new List<SyndicationItem>();
for(int i = 0 ; i < 3 ; i ++)
         SyndicationItem item = new SyndicationItem();
         item.Title = new TextSyndicationContent(“hello”+ i);
SyndicationFeed fe = new SyndicationFeed(“my feed”,”my description”,uri);
fe.Items = items;

//Add the RSS to the response
Response.ContentType = “application/rss+xml”;
Rss20FeedFormatter formater = new Rss20FeedFormatter(fe);

XmlWriter writer = XmlWriter.Create(Response.Output, null);

3 – View it in you browser or try to add it to your outlook to see the charm of creating RSS with a little effort 🙂

Reference :