Advertisment

The Vista RSS Platform 

author-image
PCQ Bureau
New Update

RSS has become the most ubiquitous ways of having information at your

fingertips. By subscribing to RSS feeds from the many different sites, you can

haveinformation delivered right to youwithout your going to it. Many RSS readers

are already available and now you can write your own RSS application for Windows

Vista without knowing the RSS XML format. In this article, we tell you how to

create one such simple RSS reader using this Vista API.In Vista, the RSS

platform consists of a number of components. Firstly, there is a Download &

Schedule engine that manages the download of syndicated content. The content can

be in any of the popular formats-RSS 0.9, 1.0, 2.0, ATOM, etc. A Merge

Processor takes care of recognizing the format and applying XSL Transformations

on the feeds, rendering them. Both these use Vista's Common Feedlist-a 'database'

of the URLs you are subscribed to. Over and above this is the RSS Object Model-a

COM API that allows you to program and use this entire platform very easily.

Advertisment
Direct

Hit!
Applies

to:
Windows developers
USP:

Learn to create RSS reader in Vista
Links:

http://msdn2.microsoft.com 
Google

keywords:
vista development

The RSS API is very simple to use. It consists of a FeedManager class that

contains a collection of FeedFolders. These in turn have a collection of Feeds,

which further contain FeedItems that contain FeedEnclosures. By adding a

reference to the FeedManager class you can easily enter the entire RSS

infrastructure on Vista and do any RSS related task like adding a new

subscription, viewing/ modifying/deleting existing feeds, etc. 

We'll create a .NET project for using the RSS API. Since this is a COM API,

all we need to do is add a reference in our solution to this. Create a new

Windows application project in VS 2005. Right click the solution and select 'Add

Reference'. In the dialog box, click the COM tab and scroll down till you can

select 'Microsoft Feeds, version 1.0'. Now in the code use the reference as:







// For the RSS Feeds COM API



using Microsoft.Feeds.interop;


using System.


// For managing COM interop


Runtime.InteropServices;




Advertisment

With this, you have RSS-enabled your application. So let's use this for actually creating an RSS reader. First drop a few controls on the form-a

Treeview, a Label, a Listbox and a Webbrowser control. Declare a variable as follows that can be used throughout the application in the main form's

class.

// The main entry into the RSS API



FeedsManager fm;

In the form's Load event, add the



following lines of code.

Advertisment

fm = new FeedsManagerClass();



IFeedFolder root = (IFeedFolder) fm.RootFolder;


EnumFolders(root);

The RSS reader created in this article will look like this when run

These lines of code get an entry into the API, find the root folder of the list

of RSS feeds you are subscribed to and then calls a function to enumerate the

feeds in the root folder. The EnumFolders method looks like this.

Advertisment

private void EnumFolders(IFeedFolder



rssFolder)


{


// If on *root* folder


if (rssFolder.name == "")


treeView1.Nodes.Add(


"RSS Feed List");


else


treeView1.Nodes.Add(


rssFolder.name);


// Get the list of feeds


IFeedsEnum rssFeeds = (IFeedsEnum) rssFolder.Feeds;


for (int i = 0; i < rssFeeds.Count; i++) {


// Get feed item


IFeed rssFeed =


(IFeed) rssFeeds.Item(i);


treeView1.Nodes<0>.Nodes.Add(


rssFeed.name);


Marshal.ReleaseComObject(


rssFeed);


}


}



















This function is very simple. It adds the name of the folder it has been

passed (or a fixed string in the case of the root folder) to the Treeview

control and the feeds in that folder as sub-items below it.

For the Treeview, we add one event handler that will let us select a node (an

RSS feed) in it that will show us more



details of the feed. For this, the following handler is written.

Advertisment

private void treeView1_AfterSelect(



object sender, TreeViewEventArgs e)


{


TreeNode selected = e.Node;


listBox1.Items.Clear();






if (selected.Text != "RSS Feed List") {



// Ensure that the item clicked was not the folder


IFeed rssFeed = (IFeed)fm.GetFeed(selected.Text);


label1.Text= rssFeed.url;


for(int i=rssFeed.itemCount-1; i>0; i--)


{


IFeedItem rssFeedItem = (IFeedItem) rssFeed.GetItem(i);


listBox1.Items.Add(


rssFeedItem.Title);


}


}


}









This function simply gets the name of the node clicked in the Treeview and

gets the Feed object corresponding to that. It then displays the URL of the RSS

feed in the Label control and the list of RSS items in the Listbox control (in

descending order-with the latest news on the top).

Advertisment

Similarly, we have an event handler for the Listbox that displays the actual

news item in the Webbrowser control when clicked:

private void listBox1_SelectedIndexChanged(object sender, EventArgs e) {



IFeed rssFeed = (IFeed)fm.GetFeed(


treeView1.SelectedNode.Text);


IFeedItem rssItem = (IFeedItem)


rssFeed.GetItem(rssFeed.itemCount -


listBox1.SelectedIndex-1);


webBrowser1.DocumentText =


rssItem.Description;


}






This event gets the news item and displays its content in the Webbrowser

control. When you run this application, you have a RSS reader that can browse

your existing subscriptions, show you the URL associated with it and all the

items already downloaded and even view the details of any news item present.

The API allows you to do a lot more-add and manage subscriptions, download

attachments or update a feed, manage list type feeds etc. You can even create

enclosure specific RSS readers -for instance, a PodCast RSS Reader that shows

only RSS feeds with audio/video attachments. You can also integrate RSS into your product to get RSS delivered news about the product or

your company right within the application itself. The limit is your imagination.

So go ahead and use the RSS API of Vista to get information at your fingertips.

Advertisment