Building a RSS reader in ASP.Net


RSS Feeds are just XMLs – so building a RSS reader is not so difficult, first you know how to do it ;-)

Let’s start with looking at C# function that reads the RSS Feeds.

First step is to collect the feeds. This is done by using WebRequest:

System.Net.WebRequest myRequest = System.Net.WebRequest.Create(rssURL);
System.Net.WebResponse myResponse = myRequest.GetResponse();
System.IO.Stream rssStream = myResponse.GetResponseStream();
System.Xml.XmlDocument rssDoc = new System.Xml.XmlDocument();

Now that we have collected the feeds, we are able to process the XML (rssDoc). In my example I would like to run though the items and then write the title.

This would look something like this:

System.Xml.XmlNodeList rssItems = rssDoc.SelectNodes("rss/channel/item");
string title = "";
string link = "";
for (int i = 0; i < rssItems.Count; i++)
    title    = rssItems.Item(i).SelectSingleNode("title").InnerText;
    link     = rssItems.Item(i).SelectSingleNode("link").InnerText;            
    Response.Write("<p><a href='" + link + "' target='new'>" + title + "</a><br/>");

That’s all, now you have a function that can collect the Feeds.

Please Notice – not all Feeds have the same XML format. They can/will differ from Feed provider to Feed provider.

Now lets take a closer look on the ASP.Net page.

<%@ Page Language="C#" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">
<script runat="server">
    public void GetFeed(string rssURL)
	//Put here the code descriped ealier in this section
<html xmlns="">
<head runat="server">
    <title>mibuso Feeds</title>    
<body style ="font-family: Tahoma,Arial,Verdana,Helvetica;">
    <form id="form1" runat="server">
                rssUrl = "";
                Response.Write("mibuso Feeds<br />");

Here we assume, that the above C# function is called GetFeed. This function must be added in a script section and can afterwards be called from the body section.

Next you place the page on the internet server. When calling it – you should get a result like this:

That’s all, now you have a ASP.Net page, that collects the feeds and show the title.

You can skip to the end and leave a response. Pinging is currently not allowed.

Leave a Reply

2 + two =