Friday, November 03, 2006 6:51 PM bart

Exploring the IE7 RSS platform in C# - Part 3

Introduction

Internet Explorer 7 introduces a unified approach to RSS. More information can be found on the RSS team blog. The good thing about it, is its availability for developers to consume the RSS feeds of the end-user, for example to build a custom RSS aggregator. Applications like the Windows Sidebar in Vista, the Windows Live Mail Desktop client, Outlook 2007 leverage the power of this API to provide multiple views on the same RSS information. In this series of blog posts I'm showing you little snippets to make a jumpstart with the RSS platform. At the end of this series, a nice (maybe geeky) application will bring together all of the pieces, so watch my RSS feed!

Getting started

For this simple demo, create a new C# Console Application in Visual Studio 2005 and add a reference to the COM component Microsoft.Feeds 1.0. This will build the required interop assembly to be used by our application to consume RSS feeds and obtain RSS information. In Program.cs import the Microsoft.Feeds.Interop namespace:

using Microsoft.Feeds.Interop;

Get notified!

The content of RSS feeds changes regularly (hopefully) so it's useful to get notified when new information is available. Luckily it's possible to do this using the API too. Here's the code:

void Main(string[] args)
{
   FeedsManager mgr = new FeedsManagerClass();
   IFeed feed = (IFeed)mgr.GetFeedByUrl("http://community.bartdesmet.net/blogs/bart/rss.aspx");

   IFeedEvents_Event
watcher = (IFeedEvents_Event)feed.GetWatcher(FEEDS_EVENTS_SCOPE.FES_ALL, FEEDS_EVENTS_MASK.FEM_FEEDEVENTS);
   watcher.FeedDownloading += new IFeedEvents_FeedDownloadingEventHandler(watcher_FeedDownloading);
   watcher.FeedDownloadCompleted += new IFeedEvents_FeedDownloadCompletedEventHandler(watcher_FeedDownloadCompleted);
   watcher.FeedItemCountChanged += new IFeedEvents_FeedItemCountChangedEventHandler(watcher_FeedItemCountChanged);

   Console.WriteLine("Downloading from " + feed.Name);
   feed.AsyncDownload();

   new AutoResetEvent(false).WaitOne();
}

static void watcher_FeedItemCountChanged(string Path, int itemCountType)
{
   Console.WriteLine("FeedItemCountChanged - Path={0}, Count={1}", Path, itemCountType);
}

static void watcher_FeedDownloadCompleted(string Path, FEEDS_DOWNLOAD_ERROR Error)
{
   Console.WriteLine("FeedDownloadCompleted - Path={0}, Error={1}", Path, Enum.GetName(typeof(FEEDS_DOWNLOAD_ERROR), Error));
}

static void watcher_FeedDownloading(string Path)
{
   Console.WriteLine("FeedDownloading - Path={0}", Path);
}

Important: Use IFeedEvents_Event as the interface type for the result of GetWatcher. Other types will result in an interop exception because interface types like IFeedEvents or IFeedWatcher or IFeedFolderWatcher cannot be casted too (due to interop restrictions).

This assumes you've subscribed to my feed on http://communities.bartdesmet.net/blogs/bart/rss.aspx via IE7. Now run the application, which should print the following (assuming the feed of my blog is outdated on your machine):

Next, go to IE7 to refresh the feed once more, to see you're notified about such updates (i.e. feed refreshes initiated by other apps):

And indeed, things work as expected:

Have fun!

kick it on DotNetKicks.com

Del.icio.us | Digg It | Technorati | Blinklist | Furl | reddit | DotNetKicks

Filed under: ,

Comments

# TechEd 2006 Developers - Day Four

Thursday, November 09, 2006 8:10 AM by B# .NET Blog

Damn God, what a busy day this was. Yesterday at our Belgian country party, organized together with Luxembourg

# TechEd 2006 Developers - Day Four

Thursday, November 09, 2006 10:05 AM by B# .NET Blog

Damn God, what a busy day this was. Yesterday at our Belgian country party, organized together with Luxembourg

# "Exploring The IE7 RSS Platform In C#" Article Series

Saturday, December 09, 2006 5:08 AM by Tom's MSDN Belux Corner

Bart De Smet explores the IE7 RSS platform using C# in an article series on his blog: Exploring the IE7

# Bart De Smet explores the IE7 RSS platform using C#

Saturday, December 09, 2006 10:59 AM by .Net Adventures

Internet Explorer 7 introduces a unified approach to RSS. The good thing about it, is its availability

# Trois articles sur l'utilisation de la Windows RSS Platform en .NET

Sunday, December 10, 2006 5:15 AM by Christophe Lauer, Blog Edition

Bart de Smet, MVP de son état, publie sur son blog une série de trois articles expliquant comment utiliser

# > MSDN France - Christophe Lauer: Trois articles sur l'utilisation de la Windows RSS Platform en .NET

Sunday, December 10, 2006 7:00 AM by Prog

Bart de Smet, MVP de son état, publie sur son blog une série de trois articles expliquant comment utiliser

# Utilisation de la Windows RSS Platform en .NET

Sunday, December 10, 2006 7:09 AM by Blog::David

Bart vient de mettre en ligne trois articles expliquant comment depuis C# utiliser la Windows RSS Platform.

# Utilisation de la Windows RSS Platform en .NET

Sunday, December 10, 2006 7:12 AM by Blog::David

Bart vient de mettre en ligne trois articles expliquant comment depuis C# utiliser la Windows RSS Platform.

# > David Tavan: Utilisation de la Windows RSS Platform en .NET

Sunday, December 10, 2006 8:16 AM by Prog

Bart vient de mettre en ligne trois articles expliquant comment depuis C# utiliser la Windows RSS Platform.

# Trois articles sur l'utilisation de la Windows RSS Platform en .NET

Sunday, December 10, 2006 8:17 AM by Prog

Bart de Smet, MVP de son état, publie sur son blog une série de trois articles expliquant comment utiliser

# Bart De Smet explores the IE7 RSS platform using C# | devintelligence.com

Pingback from  Bart De Smet explores the IE7 RSS platform using C# | devintelligence.com