Click here to Skip to main content
Click here to Skip to main content

User control to display RSS channels

, 10 Nov 2006
Rate this:
Please Sign up or sign in to vote.
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:

MainTableCss Name of the CSS style to apply to the table which contains all the feeds.
ChannelCss Name of the CSS style to apply to the name of the RSS channel.
LinkCss Name of the CSS style to apply to the link associated with the current news.
LinkCellCss Name of the CSS style to apply to the cell which contains the news title.
ContentCss Name of the CSS style to apply to the cell which contains the text of the news.
showContent If 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.
width Width of the table which contains all the feeds (pixels); if it is not specified, the default value is 100.
urls String array which contains all the RSS channel URLs to show.
newsNumber Number of news to show per channel; if it is not specified, the control will display all the news.
showContentInHtml If 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:

DownloadFeed This 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:

//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)

Share

About the Author

Pramirez
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 Pinmemberjajohnston18-Jun-09 11:51 

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

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

| Advertise | Privacy | Mobile
Web04 | 2.8.140814.1 | Last Updated 10 Nov 2006
Article Copyright 2006 by Pramirez
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid