Julie Lerman's DevLife

DevLife Part I [May 2005 - March 2007]

My Links

Blog Stats

News

A blog for DevSource.com.

This blog was originally part of the blogs.ziffdavis.com site from May 2005 through June 2007 when the blog was moved to the Movable Type blog engine and hosted at blog.devsource.com/devlife.
The original blog was eventually shut down and I was given the posts so that I could host them on my own site.


Archives

RSSToolKit for ASP.NET 2.0: Quick way to limit items from the feed

I am using the new RSSDataSource control (that is in the great RSSToolKit from Dmitry Robsman) in the new ASP.NET 2.0 site I am [finally] working on [little by little] for Vermont.NET. I wanted to expose only the last 10 items from my VTdotNET and Jobs feed that I show on the home page in DataList controls. The RSSDataSource control doesn't have such a property, but it's pretty easy to do as you would for most collections.

Rather than create the RSSDataSource visually and then set it to the DataSource property of the DataList, I am doing it in code.

Programmatically, you work with the GenericRssChannel. The GenericRSSChannel contains a collection of GenericRSSElements. You can use the channel's SelectItems property, which returns the elements as a Collections.IEnumerable, but that gives you the entire feed.

Instead, I pass the GenericRssChannel that has already loaded the rss into my ItemSubset function and attach the return value to the DataList.

Dim cVTdotNET as GenericRssChannel
cVTdotNET= GenericRssChannel.LoadChannel(
http://www.thedatafarm.com/blog/SyndicationService.asmx/GetRssCategory?categoryName=VTdotNETFeed)
MyDataList.DataSource=ItemSubset(cVTdotNET,10)

Private Function ItemSubset(ByVal rssC as GenericRssChannel,ByVal rssQuant as Int32) as ICollection
  Dim rssItems(rssQuant-1) as GenericRSSElement
  Array.Copy(rssC.Items.ToArray,rssItems, rssQuant)
  Return rssItems
End Function

posted on Tuesday, February 28, 2006 9:21 PM