Click here to Skip to main content
15,886,857 members
Articles / Web Development / ASP.NET

User control to display RSS channels

Rate me:
Please Sign up or sign in to vote.
4.33/5 (3 votes)
10 Nov 2006CPOL2 min read 28K   326   21   1
Add news content to any ASPX page, and configure the control easily.

Sample Image - rssreader.gif

Introduction

This user control displays one or more RSS channels in an HTML table. It also includes a method (not used in the example) to download the content of the channel for later use. The difference between this control and other controls or services like rss-info is that the appearance of the control can be configured with the same CSS styles used in the rest of your application.

Using the Code

Include the user control in your app and add it to the desired page.

The control has these properties:

MainTableCssName of the CSS style to apply to the table which contains all the feeds.
ChannelCssName of the CSS style to apply to the name of the RSS channel.
LinkCssName of the CSS style to apply to the link associated with the current news.
LinkCellCssName of the CSS style to apply to the cell which contains the news title.
ContentCssName of the CSS style to apply to the cell which contains the text of the news.
showContentIf this flag is true, the content of the news will be displayed; otherwise, only the title and link will be displayed. The default value is false.
widthWidth of the table which contains all the feeds (pixels); if it is not specified, the default value is 100.
urlsString array which contains all the RSS channel URLs to show.
newsNumberNumber of news to show per channel; if it is not specified, the control will display all the news.
showContentInHtmlIf the flag is true, the content of the news will be displayed as HTML; otherwise, it will be displayed in text format. The default format is text.

And a method:

DownloadFeedThis function returns all the data returned to the browser by a URL. This can be an HTML page or whatever; you can use this string to save the content to a file.

Example use:

C#
//This code is in the example aspx.cs page

string [] channels= new string[3];
channels[0] = "http://rssfeeds.usatoday.com/usatoday-HorseRacing";
channels[1] = "http://www.horse-races.net/HRN-rssfeed.xml";
channels[2] = "http://news.google.com.mx/nwshp?client=firefox-a&rls" + 
              "=org.mozilla:es-ES:official&ie=UTF-8&oe=UTF-8&hl=" + 
              "es&client=firefox-a&rls=org.mozilla:es-ES:" + 
              "official_s&tab=wn&q=&output=rss";

Rssfeed1.urls = channels;
Rssfeed1.width = 150;
Rssfeed1.showContent = true;
Rssfeed1.showContentInHtml = true;
Rssfeed1.ChannelCss = "GrayBackgroundActive";
Rssfeed1.ContentCss = "NormalLetter";
Rssfeed1.LinkCss = "projectletter";
Rssfeed1.newsNumber = 3;

Points of Interest

The control uses a dataset to populate the table, and that dataset is filled directly from the RSS channel with the method ReadXml(), but some channels throw an error because the item "link" is repeated in the same node; when this happens, you will see an error.

In this case, you could use the method DownloadFeed of the control to download the content of the channel and parse it as you wish. But the control works fine with most RSS channels; in the sample code, the Google News channel and two othres are used.

License

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


Written By
Web Developer
Mexico Mexico
I am Pedro Ramirez from mexico, work for www.sciodev.com, the company is located in Mexico, we do outsourcing and nearshore development, we are focused on SaaS nearshore development, I started with VB.Net, but now I am ambidextrous using VB.Net or C#.

Comments and Discussions

 
GeneralMy vote of 1 Pin
jajohnston18-Jun-09 11:51
jajohnston18-Jun-09 11:51 
nice idea. doesn't work.

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.