Easy RSS Syndication in .NET
May 26, 2011
Posted by on
My office colleague just asked me about the easy way to read and retrieve an RSS feed for a specific or multiple sites. And I say that Microsoft did indeed has a class called Syndication that resides under System.ServiceModel namespace that handles not only RSS but also Atom format too!
Below is a console application that I created to show how easy it is to read RSS via .NET:
Declare the import:
1: using System.ServiceModel.Syndication;
Make sure you add the ServiceModel and ServiceModel.Web on your Reference.
Basically, the main logic for reading RSS is to call the Url via the WebClient class and create an XmlReader object to hold/read the XML results being fetched on the WebClient request. And then, finally, just pass the XmlReader object to the Syndication object and it will parse all results into a feed collection.
and the Main() call would just be:
And when I run the project, the output will look similar on the screenshot below:
Simple as that!
The RSSConsole Project File for this snippet is available for download here.