HOW TO build your own RSS/Atom Feed Reader with one line of code

Using the RssDataSource control of the ASP.Net RssToolkit Version 2.0, fetching a RSS feed, binding to a data control like the GridView can all be done declaratively and rolling out your own RSS/Atom Reader/Aggregator is a cinch. I learnt about the free RSS Toolkit - which makes consuming and exposing RSS feeds in ASP.NET super easy, from Scott Gu's weekly link-listing series. One link led to the other and while monkeying around with the RssToolkit controls, I thought cranking up a frill-free ASP.NET Forums feed aggregator that updates itself at intervals would be a worthwhile thing to do. Knowing that the ASP.NET AJAX Timer would be helpful for this, I set about building my app.
  • I started by choosing the ASP.NET AJAX-enabled Web site template.
  • Moving to Design mode, I dropped a ASP.NET AJAX UpdatePanel & Timer controls.
  • Into the UpdatePanel I dropped the RssDataSource.
  • Clicking on its Smart Tag prompter, you can provide the ASP.NET Forums RSS Feed URL http://forums.asp.net/aggregaterss.aspx?Mode=0 in the dialog box that opens from "RssDataSource Tasks" > "Configure Data Source".
  • Clicking on the Smart Tag prompter for GridView shows us the commonly used "GridView Tasks". In the "Choose Data Source" dropdown the RssDataSource control is already there ready to be bound.
  • We can pick the columns that are of our interest. I choose the title, link, description & pubDate columns.
  • I merged the title & link columns into a hyperlink field.
  • I did not disturb the Timer control's default Interval value of 5 minutes but set the RssDataSource control's MaxItems value to 10.
  • To refresh the grid with the latest data, I just had to add a single line of code to the Timer's Tick event:
protected void Timer1_Tick(object sender, EventArgs e) { GridView1.DataBind(); Label1.Text = "Page refreshed at: " + DateTime.Now.ToLongTimeString(); } The final code to build this bare-bones aggregator looks like this.

Comments