A Simple RSS Reader

In this post I thought of publishing a code snippet regarding how to build a simple RSS reader. Here I explained how to build a RSS reader as a user control so that you can re-use it among your web applications.

Follow these steps…

  1. Open VS 2005 & create a new project.
  2. Right-click the project title & select Add New Item. Then from the templates select Web User Control. Name that as ‘RSSList’.
  3. Go to the source view of the user control and put the following code.

  4. <%@ Control Language=”C#” AutoEventWireup=”true” CodeFile=”RSSList.ascx.cs” Inherits=”RSSList” %>
    <%@ OutputCache Duration=”3600″ VaryByParam=”None” %>

    <asp:Repeater ID=”Repeater1″ runat=”server”>
    <table border=0 style=”width: 240px; font-size: x-small; color: black; font-family: Verdana;”>
    <tr style=”font-weight: bold;”>
    <tr style=”font-style: italic;”>

    <tr bgcolor=”LightBlue” >
    <a target=”article” style=”text-decoration: none; color: black;” href=<%# DataBinder.Eval(Container.DataItem, “link”) %>>
    <%# DataBinder.Eval(Container.DataItem, “title”) %> </a>
    <tr bgcolor=”Ivory”>
    <td style=”color: CornflowerBlue;”>
    <%# DataBinder.Eval(Container.DataItem, “description”) %>
    <tr style=”font-size: x-small; color: black; font-family: Verdana;”>
    <%#DataBinder.Eval(Container.DataItem, “pubDate”)%>


  5. Now open the RSSList.ascx.cs file & put the follwing code..

  6. using System;
    using System.Data;
    using System.Configuration;
    using System.Collections;
    using System.Web;
    using System.Web.Security;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.WebParts;
    using System.Web.UI.HtmlControls;
    using System.Net;
    using System.Data;

    public partial class RSSList : System.Web.UI.UserControl

    public string Title;
    public string Description;

    protected void Page_Load(object sender, EventArgs e)
    DataSet _rssData = RefreshFeed();

    object[] channelItems = _rssData.Tables[1].Rows[0].ItemArray;
    int titleColumn = _rssData.Tables[1].Columns[“title”].Ordinal;
    int descriptionColumn = _rssData.Tables[1].Columns[“description”].Ordinal;
    Title = channelItems.GetValue(titleColumn).ToString();
    Description = channelItems.GetValue(descriptionColumn).ToString();

    Repeater1.DataSource = _rssData.Tables[2];


    private DataSet RefreshFeed()
    HttpWebRequest rssFeed = (HttpWebRequest)WebRequest.Create(“http://localhost/Search1/Rss.xml&#8221;);
    DataSet rssData = new DataSet();

    return rssData;


  7. Now here you can give any web address of a rss news channel, but for this example I used my own xml file called ‘Rss.xml’ which is inside my IIS virtual directory. For your convenience I’ll publish my Rss.xml file at the end.
  8. Now our user control is ok, we need to test it. Therefore create a new aspx page and simply drag & drop the RSSList.acsx from the solution explorer to the design view of the page.
  9. Now you can see a new control in the design view of the page. Now our work is done. Simply run the web application.
  10. If you use my Rss.xml file you have to put it inside same virtual directory structure that I have used as in this example.
  11. When you run the application you ‘ll be able to see the News items from the news chanel that you’ve provided. (In my example it is Rss.xml)
  12. Enjoy…!!

This is my Rss.xml file…

<rss version=”2.0″>
<title>Liftoff News</title> </channel></rss>
<link />http://liftoff.msfc.nasa.gov/ <description>Liftoff to Space Exploration.</description>
<pubdate>Tue, 10 Jun 2003 04:00:00 GMT</pubdate> <lastbuilddate>Tue, 10 Jun 2003 09:41:01 GMT</lastbuilddate>
<generator>Weblog Editor 2.0</generator>
<title>Second post</title>
<description>This is a sample description for the second post..</description>
<time>10/16/2006 10:26:25 AM</time>
<title>First post</title>
<description>here goes some sample description for the first post. I updated this news.</description>
<time>10/16/2006 10:27:34 AM</time>
<title>Star City</title> </item>
<link />http://liftoff.msfc.nasa.gov/news/2003/news-starcity.asp <description>How do Americans get ready to work with Russians aboard the
International Space Station? They take a crash course in culture, language
and protocol at Russia’s Star City.</description>
<pubdate>Tue, 03 Jun 2003 09:39:21 GMT</pubdate> <guid>http://liftoff.msfc.nasa.gov/2003/06/03.html#item573</guid&gt;
<time>10/10/2006 1:22:27 PM</time>

<title>Space Exploration</title> </item>
<link />http://liftoff.msfc.nasa.gov/ <description>Sky watchers in Europe, Asia, and parts of Alaska and Canada
will experience a partial eclipse of the Sun on Saturday, May 31st.</description>
<pubdate>Fri, 30 May 2003 11:06:42 GMT</pubdate> <guid>http://liftoff.msfc.nasa.gov/2003/05/30.html#item572</guid&gt;
<time>10/10/2006 1:11:27 PM</time>

<title>The Engine That Does More</title> </item>
<link />http://liftoff.msfc.nasa.gov/news/2003/news-VASIMR.asp <description>Before man travels to Mars, NASA hopes to design new engines
that will let us fly through the Solar System more quickly. The proposed
VASIMR engine would do that.</description>
<pubdate>Tue, 27 May 2003 08:37:32 GMT</pubdate> <guid>http://liftoff.msfc.nasa.gov/2003/05/27.html#item571</guid&gt;
<time>10/10/2006 1:44:27 PM</time>

<title>Astronauts’ Dirty Laundry</title> </item>
<link />http://liftoff.msfc.nasa.gov/news/2003/news-laundry.asp <description>Compared to earlier spacecraft, the International Space
Station has many luxuries, but laundry facilities are not one of them.
Instead, astronauts have other options.</description>
<pubdate>Tue, 20 May 2003 08:56:02 GMT</pubdate> <guid>http://liftoff.msfc.nasa.gov/2003/05/20.html#item570</guid&gt;
<time>10/10/2006 1:31:27 PM</time>


One thought on “A Simple RSS Reader

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s