Click here to Skip to main content
15,884,472 members
Articles / Web Development / ASP.NET
Tip/Trick

Read RSS FEED data (blogspot.com)

Rate me:
Please Sign up or sign in to vote.
5.00/5 (2 votes)
10 Nov 2011CPOL1 min read 14.6K   3   1
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.NET
    <asp:DataGrid runat="server" ID="myPosts" AutoGenerateColumns="False">
        <columns>
            <asp:TemplateColumn HeaderText="My Posts">
                <itemtemplate>
                    <a href="<%# DataBinder.Eval(Container.DataItem, " link=")%>">
                        <%# DataBinder.Eval(Container.DataItem, "title") %>
                    </a>
                </itemtemplate>
        </columns>
    

  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:
    C#
    XmlTextReader reader = new XmlTextReader("http://bgsuryablog.blogspot.com/rss.xml");


  3. We will declare Dataset:
    C#
    DataSet ds = new DataSet();


  4. To read XML data & read into DS, let's use the below code:
    C#
    ds.ReadXml(reader);


  5. As we have dataset object filled up with RSS feed data, let's assign Dataset to datagrid as below:
    C#
    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!

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



Comments and Discussions

 
Questioncommnet Pin
Sarah MQ16-Feb-14 20:38
Sarah MQ16-Feb-14 20:38 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.