In this post, we will see how to read RSS Feed data & show it on our web site.
To start with, we need to know from where we are going to 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://xxxxxx.blogspot.com, then RSS feed data would be available at http://xxxxx.blogspot.com/rss.xml. So this is the source data for us to work with.
Now start with code part:
- First let's add
DataGrid to our web page, with one template column as shown below:
<asp:DataGrid runat="server" ID="myPosts" AutoGenerateColumns="False">
<asp:TemplateColumn HeaderText="My Posts">
<a href="<%# DataBinder.Eval(Container.DataItem, " link=")%>">
<%# DataBinder.Eval(Container.DataItem, "title") %>
- In our page load, let's declare
XMLTextReader object & this will take RSS FEED URL. In this example, I am using my blogspot URL:
XmlTextReader reader = new XmlTextReader("http://bgsuryablog.blogspot.com/rss.xml");
- We will declare
DataSet ds = new DataSet();
- To read XML data & read into DS, let's use the below code:
- As we have
dataset object filled up with RSS feed data, let's assign
datagrid as below:
myPosts.DataSource = ds;
Dataset object would contain properties in the form of Link & Title, which we have used in our .aspx code i.e. step 1.
- Now execute the code & see the output.
Happy coding… hope this helps!