Home » Code | ASP.NET

Syndication Feeds in 3.5

9. September 2009 by thebeebs 0 Comments

A new namespace added to .net 3.5 is System.ServiceModel.Syndication namespace it may have slipped in without you noticing, but if your planning on doing any thing with RSS 2.0 or Atom 1.0 feeds then you might want to take a look because they’ve done an awful lot of leg work for you.

To create an RSS feed we will first need to set up a page, We’ll call it rss.aspx

Rss

Add rss.aspx to your site and go to the code view. In the Page_Load section of you code the change the response.ContentType to application/rss+xml which tells the requesting browser to expect RSS data from the server.

ContentType

Directly under that, create a new SyndicationFeed and populate the main settings of the feed, the title and description etc. You could obviously pull this information from a database but I've chosen to hard code this example.

FeedSettings

Next we create the syndication Items and add them to the SyndicationFeed.

FeedItems

Next we set up an XMLWriter and create it with the Response.OutputStream and the XMlWriter setting object we create on lines 42 and 43. This will send the XML to the Browser when we close it on line 49.

On line 46 and 47 we create an RSS Formatter which will convert our SyndicationFeed into the correct format for RSS, there is also an ATOM formatter built into the frame work. If we were to use that one we would also need to change the Response.Content Type on line 14 to “application/atom+xml”

rssXmlWriter

Download Code Here

Comments

Add comment


(Will show your Gravatar icon)  

  Country flag

biuquote
  • Comment
  • Preview
Loading