<body><script type="text/javascript"> function setAttributeOnload(object, attribute, val) { if(window.addEventListener) { window.addEventListener('load', function(){ object[attribute] = val; }, false); } else { window.attachEvent('onload', function(){ object[attribute] = val; }); } } </script> <div id="navbar-iframe-container"></div> <script type="text/javascript" src="https://apis.google.com/js/plusone.js"></script> <script type="text/javascript"> gapi.load("gapi.iframes:gapi.iframes.style.bubble", function() { if (gapi.iframes && gapi.iframes.getContext) { gapi.iframes.getContext().openChild({ url: 'https://www.blogger.com/navbar.g?targetBlogID\x3d8211560\x26blogName\x3dTech+Tips,+Tricks+%26+Trivia\x26publishMode\x3dPUBLISH_MODE_BLOGSPOT\x26navbarType\x3dBLUE\x26layoutType\x3dCLASSIC\x26searchRoot\x3dhttp://mvark.blogspot.com/search\x26blogLocale\x3den\x26v\x3d2\x26homepageUrl\x3dhttp://mvark.blogspot.com/\x26vt\x3d-5147029996388199615', where: document.getElementById("navbar-iframe-container"), id: "navbar-iframe" }); } }); </script>

Tech Tips, Tricks & Trivia

by 'Anil' Radhakrishna
An architect's notes, experiments, discoveries and annotated bookmarks.

Search from over a hundred HOW TO articles, Tips and Tricks


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.

Labels: , ,

Tweet this | Google+ it | Share on FB

« Home | Next »
| Next »
| Next »
| Next »
| Next »
| Next »
| Next »
| Next »
| Next »
| Next »

»

Post a Comment