Friday 18 September 2009

Read RSS and Atom feed in C#

I had a requirement to read RSS/Atom feeds from blogs and store in SharePoint List.
I remember we had to go for separate framework to read the feeds and parse it. In that case we need to refer the framework in our project and install that assembly in Bin or GAC.

Now with .Net 3.5, life has become much easier.

Yes, with the namespace 'System.ServiceModel.Syndication' it is just few lines of code to read and parse the feeds either RSS or Atom.

Just add reference to 'System.ServiceModel.Web' to your project and include above namespace in your class, thats it.

Below is the code i used.
XmlReader reader = XmlReader.Create(curUrl);
SyndicationFeed feed = SyndicationFeed.Load(reader);
string title = String.Empty;
string link = String.Emplty;
DateTime dateTime = null;
foreach (var feeditem in feed.Items)
{
title = feeditem.Title.Text;
dateTime = feeditem.PublishDate.LocalDateTime;
link = feeditem.Links[feeditem.Links.Count -1].Uri.OriginalString;

//Do your tasks here
}

Easy to deploy and maintain too.
Happy Coding
வாழ்க வளமுடன் :)

Useful SharePoint Links

Some Useful SharePoint links


Accessing Data from Workflow Association and Initiation Forms in Windows SharePoint Services 3.0
Best Practices: Common Coding Issues When Using the SharePoint Object Model
Best Practices: Using Disposable Windows SharePoint Services Objects
Checklist for Creating SharePoint Web Parts
Creating Custom Timer Jobs in Windows SharePoint Services 3.0
Creating a Windows SharePoint Services 3.0 Custom Field by Using the EntityPicker
Creating a Windows SharePoint Services 3.0 Web Part Using Visual Studio 2005 Extensions
Development Tools and Techniques for Working with Code in Windows SharePoint Services 3.0 (Part 1 of 2)
Development Tools and Techniques for Working with Code in Windows SharePoint Services 3.0 (Part 2 of 2)
Securing Application Pages in Windows SharePoint Services 3.0
Selective Content Migration in Windows SharePoint Services 3.0
Understanding and Creating Customized and Uncustomized Files in Windows SharePoint Services 3.0
Understanding the Administrative Object Model of Windows SharePoint Services 3.0
Usage Event Logging in Windows SharePoint Services 3.0
Using Solution Packages to Deploy Features and Content in Windows SharePoint Services 3.0
Workflow Scalability and Performance in Windows SharePoint Services 3.0
Working with ASP.NET 2.0 Web Parts and Windows SharePoint Services 3.0