Working with the Windows RSS Platform (C#)

If you don’t know what RSS is, then you have been hiding under a pretty big rock lately. A lot of Microsoft’s products are currently out or are coming out in the next year use the Windows RSS platform. To name a few of these products off the top of my head are as follows: IE7, Office 2007, Windows Live Mail Desktop, and Windows Vista. I’m pretty sure that sometime in the next couple of years you will more than likely be working with RSS in one or more of your applications.

During the past week I have been working with the Windows RSS platform in one of my applications. My adventure into the unknown lands of the Windows RSS platform was quite an experience; I found out that the MSDN documentation tends to be very helpful, but real world examples tend to be a little scarce.

For that reason, I’ll show you how to easy it is to use the Windows RSS platform in your C# 2.0 Application to create an IE7 Feed in the root or subfolder of the Feeds Folder.

  1. Open Visual Studio 2005 and create a new Windows Application.
  2. Open the Solution Explorer and right click References and click “Add”.
  3. Switch to the COM tab and find “Microsoft Feeds, version 1.0”.

     

    You should now see “Microsoft.Feeds.Interop” in your References List.

  4. Add “ using Microsoft.Feeds.Interop ;” to the top of your Form1.cs
  5. Create  a new method called AddIE7Feed that returns a Boolean and takes 3 String parameters (folder, URL, title).

    It should look like this:

    private bool AddIE7Feed(string folder, string url, string title)

    {

    return true;

    }

  6. Next lets add some code to AddIE7Feed.
    FeedsManager fm = new FeedsManager();
    IFeedFolder rootFolder = (IFeedFolder)fm.RootFolder;
    IFeedFolder subFolder = rootFolder; 

    try

    {
    //if a folderpath is supplied the following code is executed.

    if (folder != string.Empty)

    {

    //checks to see if the folder exists.

    if (!rootFolder.ExistsSubfolder(folder))

    {

    //creates the folder if it does not exist.
    rootFolder.CreateSubfolder(folder);
    //set the subFolder to the new folder.
    subFolder = (IFeedFolder)rootFolder.GetSubfolder(folder);

    }

    }

    //checks to see if the feed exists (by checking the url and title).

    if (!subFolder.ExistsFeed(title) && !fm.IsSubscribed(url))

    {

    //creates the feed if it does not exist.
    subFolder.CreateFeed(title, url);
    return true;

    }

    return false;

    }

    //catches any Exception that may be throw
    catch (Exception) {
    return false;

    }

  7. Let s add a feed by adding a few lines of code in the Form1_Load

    //Please note if the url to the feed already exisits anywhere in the feeds folder an exception will occur.

    //Add a feed called "windowscoding.com" to the root feeds folder.

    if (AddIE7Feed("", "http://windowscoding.com/blogs/MainFeed.aspx", "windowscoding.com"))

    {

    MessageBox.Show("Feed was added successfully");

    }

    else

    {

    MessageBox.Show("Failed to add the Feed");

    }

    //close the application.

    this.Close();

  8. Run the application and then open IE7 and you should see the feed above.

 

  I know that this application does not have any User Interface it is purely meant to be an example on how to use the Windows RSS Platform with IE7.

 

I have compiled a list of links that I believe anyone working with the Windows RSS platform should read.

Microsoft Team RSS Blog

http://blogs.msdn.com/rssteam

Windows RSS Platform Reference

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/feedsapi/rss/reference/entry.asp

Using the Windows RSS Platform

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/feedsapi/rss/overviews/msfeeds_ovw.asp

Valid Feed and Folder Names (Must Read)

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/feedsapi/rss/overviews/name_ovw.asp

 

To download the Visual Studio project and source follow the link below.

Working with the Windows RSS Platform Sample Application (C#)

 

Please note that the code in section six has been updated. In some circumstances if you only check if the feed exists by the name an exception will be thrown.


Posted Jul 17 2006, 05:24 AM by Blake Niemyjski |
Filed under: , ,


Comments 

Top 50 Contributor
Joined on 04-24-2009
re: Working with the Windows RSS Platform (C#) Posted on Apr 24 2009, 05:47 AM

how can i get  the url of this subscribed feed?

[C#]Windows RSS Platform Posted on Apr 18 2011, 10:18 AM

[C#]Windows RSS Platform

windowscoding.com;
Copyright © 2008 Windows Coding
Microsoft and Microsoft logo's are trademarks of Microsoft Corporation.