Hi, I'm Karl.

And this is Jambr...

... my attempt at documenting my adventures as a developer.

I regularly come across, or generally do quite interesting things in my day job, so when I have some time I try and write about them. Hopefully you'll find some of the Articles handy.

Karl Stoney

Article » Creating an RSS 2.0 feed with .NET Syndication Namespace

Creating an RSS 2.0 feed with .NET Syndication Namespace

Creating an RSS 2.0 feed using .NET Syndication

Overview

In my Previous Post I demonstrated how to create an RSS feed using an XML Document.

This got some attention as it was pointed out to me that I could achieve the same result using the .NET Syndication classes.  As a result I have created this programming article with an alternate version of the class, which does away with the XMLDocument manipulation and uses these Syndication classes.

As with any default namespaces and classes in the .NET framework, they expose a lot of things that I quite simply don't need for my simple News or Article RSS feed, so I have wrapped them up as I did last time into a utility class, which enables you to quickly and easily create your feed.

Using the code

The code is available for download here, simply put it into your project and add a reference to yourprojectnamespace.Syndication.  Using the code is very simple, see this example:

'Create your feed
Dim rssfeed As New RSSFeed("Your RSS Feed Title",
                           "The description of your feed",
                           "The URL to the feed",
                           "A unique identifier for your feed",
                           Now,
                           "en-GB")

'Add a category to the main channel
rssfeed.AddFeedCategory("CodeProject", "http://www.codeproject.com", "CodeProject")

'Add an item
dim item = rssfeed.AddItem("Item Title",
                           "Item Description",
                           "Item Body",
                           "Item URL",
                           "A unique identifier for your item",
                           Now,
                           "The author name")

'Add a category to the item
item.Categories.Add(New SyndicationCategory("CodeProject","http://www.codeproject.com","CodeProject"))

'Output the result
Return Content(rssfeed.ToString(rssfeed.OutputType.RSS2), "text/xml")

Notes

Because we're now using the syndication provider, you can chose to output as RSS2 or Atom1 by changing the parameter in the ToString method.

This is utilising the helper class as previous to ensure the xml document is UTF8, the resultant XML passes the RSS Feed Validator, and works perfectly with Code Project.

As usual, any questions please ask.

 
Karl
 
983
 
0
 
.NET, RSS

Comments » Creating an RSS 2.0 feed with .NET Syndication Namespace

Add your own comment

You need to be Logged In to post comments.

Adverts

Recent Articles

Recent Blog Items