65.9K
CodeProject is changing. Read more.
Home

Read RSS FEED data (blogspot.com)

Nov 8, 2011

CPOL

1 min read

viewsIcon

15164

Read RSS FEED data (blogspot.com)

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:
  1. 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">
                        
                            
                                <%# DataBinder.Eval(Container.DataItem, "title") %>
                            
                                        
                       
    
  2. 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");
  3. We will declare Dataset:
    DataSet ds = new DataSet();
  4. To read XML data & read into DS, let's use the below code:
    ds.ReadXml(reader);
  5. As we have dataset object filled up with RSS feed data, let's 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. step 1.
  7. Now execute the code & see the output.
Happy coding… hope this helps!