When you think ASP, think...
Recent Articles xml
All Articles
ASP.NET Articles
Related Web Technologies
User Tips!
Coding Tips
spgif spgif

Book Reviews
Sample Chapters
JavaScript Tutorials
MSDN Communities Hub
Official Docs
Stump the SQL Guru!
Web Hosts
Author an Article
spgif spgif

ASP ASP.NET ASP FAQs Feedback topnav-right
Print this Page!
Published: Wednesday, September 28, 2005

Displaying RSS Feeds - A Look at RssFeed Version 1.9

By Scott Mitchell


Over the past several years one of the growing trends in the Internet space has been syndication, the process of providing a site's content through a machine-readable file (i.e., an XML-formatted file). Once a site's content is marked up in a machine-readable format, there are a multitude of ways that that data can begin to be utilized. The most common way is through aggregators, which are programs designed to periodically cull through a list of syndication feeds and download any new content. (There are a variety of aggregator programs, from desktop based ones like RssBandit to online ones like BlogLines and My Yahoo!.) More interestingly, the site content, now able to be parsed by a program, can more easily be searched, customized, categorized, and analyzed. And, as we'll see in this article, content from another site can easily be injected into your own site by having your ASP.NET pages retrieve the remote syndicated content, parse it, and display it.

Site syndication has been an idea that has been around for over a decade, but didn't enjoy wide-spread adoption until bloggers started using it to make it easier for their friends and readership to easily receive new content. Since then, many large websites have jumped on the syndication bandwagon, including ABC News, ESPN, Yahoo! News, Microsoft MSDN, and so on. There are a couple of syndication standards used, the most popular (at this time) being RSS version 2.0, where RSS stands for Really Simple Syndication. There are other syndication formats, however, which are discussed briefly further on in this article.

In a previous article on mine, A Custom ASP.NET Server Control for Displaying RSS Feeds, I looked at using a free, open-source ASP.NET server control that I created in order to display syndicated content from another site on an ASP.NET website. This server control, called RssFeed, has recently been updated to include some new, neat, snazzy features. In this article we'll take a quick look at RssFeed and then highlight some of its new features. Read on to learn more!

- continued -

A Quick Look at RssFeed

As the popularity of blogging began to take off a couple years ago, I wanted an easy way to display the latest blog content here on 4Guys. To accomplish this, I decided to create a custom, compiled, ASP.NET server control that could be used to effortlessly display syndicated content. In October 2003 I created RssFeed to tackle this very task - in fact, you can see it in action here on 4Guys in the recommended blogs section.

Using RssFeed is as simply as dragging a control from the Visual Studio Toolbox onto your page and then writing a scant two lines of code:

RssFeedID.DataSource = url_to_RSS_feed

That's all there is to displaying the contents of an RSS feed in an ASP.NET page. While the default output looks pretty bleh, there are a number of RssFeed properties that you can use to enhance the appearance of the blog. Additionally, RssFeed supports templates, so you can provide a great deal of customization, adding in your own HTML markup and other Web controls interspersed with the RSS feed's content, precisely as you specify it. The screenshot below shows an example of using RssFeed to display the latest U.S. headlines from Yahoo! News. For more examples of customizing the look and feel of RssFeed check out the RssFeed live demos.

For information on getting started with RssFeed - how to download, how to add the RssFeed control to your Visual Studio Toolbox, and so on - refer to A Custom ASP.NET Server Control for Displaying RSS Feeds and the official RssFeed homepage.

The Main Shortcoming of RssFeed - Where's Atom Support?

In my opinion, RssFeed, even in its current version, suffers from one major shortcoming: it only provides support for the RSS syndication format. A little history: back when blogs began emerging there was some instability in the syndication format space. This led to two versions of RSS forking - RSS 1.0 (sometimes called the RDF specification) and what eventually became RSS 2.0. (You can read more about the RDF/RSS fork at Web RSS History.) RssFeed supports feeds in both RSS 1.0 (RDF) and RSS 2.0 formats.

However, since that time, a third standard has emerged - Atom. At this point, RssFeed does not support Atom. It is my intention, however, to add support for this alternate syndication specification in due time. For now, however, RssFeed will only work with those syndicated fees using some flavor of RSS. Fortunately, most sites I've seen syndicate using RSS or RDF, and many that include an Atom option also have RSS variants available.

Decoupling Display and Feed Retrieval

Previous to RssFeed version 1.9, there was a tight coupling between the rendering of the ASP.NET server control and the actual retrieval and parsing of the syndication feed. That is, prior to version 1.9, the code that made the HTTP request, parsed the retrieved XML, and serialized the items into appropriate class instances was embedded within the actual ASP.NET server control class.

With version 1.9 this logic has been moved out into a separate class, RssEngine. This means that RssFeed now supports two usage patterns:

  1. You can use RssFeed as it was originally intended, to display the contents of an RSS syndication feed within an ASP.NET page, or
  2. You can use the RssEngine class to grab and parse an RSS feed, at which point you can programmatically work the resulting data. Maybe you want to dump the contents to a database, or perhaps you need to analyze the data in some manner. This is now very easy with RssFeed version 1.9.

Let's look at a demo that illustrates how one can now programmatically work with the contents of a feed using RssFeed. For example, imagine that we wanted to pull down a particular RSS feed and search its items for a description that contains a particular keyword, say "ASP.NET". This could be easily accomplished using the following code:

// Create the RssEngine
RssEngine engine = new RssEngine();

// Grab the content
RssDocument doc = engine.GetDataSource("https://aspnet.4guysfromrolla.com/rss/rss.aspx");

// See if there are any instances of "ASP.NET" in the items' descriptions
foreach (RssItem item in doc.Items)
  if (item.Description.IndexOf("ASP.NET") >= 0)
     ... output the Title and Description properties of the item ...
[View a Live Demo!]

As the code illustrates, grabbing and working with an RSS feed is as simple as creating the RssEngine class, calling its GetDataSource() method, and then programmatically working with the resulting RssDocument object. The RssDocument has properties that represent an RSS feed, properties like Title, Link, PubDate, and Items. The Items property is a collection of RssItem instances, each of which represents a syndicated item. The RssItem class has properties like Title, Link, Description, PubDate, and Author, among others.

Displaying Podcast Information with RssFeed

In addition to decoupling the RSS feed slurping engine from the ASP.NET server control code, RssFeed version 1.9 also introduces the RssEnclosure class. The RSS 2.0 standard spells out an optional <enclosure> element that, if provided, can be used to specify some media file that is associated with the feed item. This element is commonly used in podcasting. When syndicating a podcast, the <enclosure> element contains a reference to the MP3 file.

Now that RssFeed version 1.9 reads in the <enclosure> element, you can easily use RssFeed to display content from a podcast. The RssEnclosure class has three properties:

  • Url - the URL to the media file,
  • Length - the size of the file (in bytes), and
  • Type - the MIME type of the file
The RssItem class contains an RssEnclosure property. Podcast information can be displayed in one of two ways: you can use the default display, which will add an "Enclosure" column to the resulting output if you set the ShowEnclosure property to True; or you can use RssFeed's ItemTemplate to emit the enclosure information using databinding syntax (a la <%# DataBinder.Eval(Container.DataItem, "RssEnclosure.Url") %>).

Putting this all together I can use RssFeed to display information from the local NPR news, which, for San Diego, is podcasted at http://kpbs.org/news/podcast/. The screenshot below shows the output of RssFeed after I set the ShowEnclosure property to True.

Note that not all entires for the news have included enclosures; only those that do have the Download link. Clicking the Download link will download the item's associated MP3 file. You can also see a live demo of this functionality.


Whereas syndicated content was once squarely in the realm of blogs and techie sites, more and more "mainstream" websites are employing syndication through RSS. Since this syndicated content is presented in a standardized, machine-readable format, programs can be created that utilize the syndicated data. RssFeed is one such component, providing both an RSS engine for downloading RDF or RSS feeds as well as an ASP.NET server control for displaying feeds in an ASP.NET page. Also, with version 1.9, the <enclosure> element is supported, making it easy to display podcast feeds on a webpage.

If you are interested in learning more about RssFeed be sure to check out the official page. It has links to download the source code, various live demos, helpful articles, and complete online and offline documentation.

Happy Programming!

  • By Scott Mitchell


  • RssFeed Homepage
  • A plethora of live demos

  • ASP.NET [1.x] [2.0] | ASPMessageboard.com | ASPFAQs.com | Advertise | Feedback | Author an Article