Friday 29 June 2012

RSS Feed data fetch in Asp.net web application



Here we will see how to read RSS Feed data  and  show it on our web site.

To start with on we need to know from where we are going read RSS feed data. 
In this example, we will read RSS feed data from blogger.com site, where recent posts are available.
Let’s say there is a blog spot as http://yyyyyyy.blogspot.com then RSS feed data would be available at http://yyyyyyy.blogspot.com/rss.xml. So this is the source data for us to work with.
Now start with code part:
1. First lets add DataGrid to our web page, with one template column as shown below
<%# DataBinder.Eval(Container.DataItem, “title”) %>
2. In our page load, lets declare XMLTextReader object with & this will take RSS FEED URL. 
In this example I am using my blogspot url
XmlTextReader reader = new XmlTextReader(”http://TechTeraByte.blogspot.com/rss.xml“);
3. We will declare Dataset
DataSet ds = new DataSet();

4. To read XML data & read into DS lets use below code
ds.ReadXml(reader);

5. As we have dataset object filled up with RSS feed data. Lets assign Dataset to datagrid as below

myPosts.DataSource = ds;
myPosts.DataBind();

6. Dataset object would contain properties in the form of Link & Title, which we have used in our .aspx code
 i.e. step1

7. Now execute the code,,,,,, END

No comments:

Post a Comment