Generating RSS Feeds for SharePoint Sites

UPDATED HERE!!

Today I have a day off, so I decided to work a little bit on my “pet project”: RSS generation for SharePoint sites. Scoble asked for it when I released my RSS Reader Webpart. I know there are some good solutions for this problem available (for example from Siegfried Weber and DevHawk), but I was intrigued by this problem so I decided to craft one myself. Et voila: the What’s New Rss Feed for SharePoint was born (see the end of the post for downloads). I’ve re-used to logic of the What’s New Web Part to retrieve the latest changes on a SharePoint site so I won’t go into detail about that part of the code. The general idea behind this is that the code will go through all the lists on a SharePoint site (you can exclude specific lists) and retrieves the latest changed items (you can specify how many).

An APSX page will build the RSS Feed (more details the actual RSS generation later on) and will use the SharePoint object model to access the contents of a specific SharePoint site. The tricky part here is how the ASPX page can access the SharePoint object model. This issue is solved by deploying the ASPX page to the _VTI_BIN directory of a SharePoint site. You may have noticed this, but this directory is kind-a special: this directory is accessible from each SharePoint site, e.g.: http://sharepoint.leadit.be/_vti_bin/... , http://sharepoint.leadit.be/SubSite/_vti_bin/... . It doesn’t matter which URL you use, you’ll always end up in the same virtual _VTI_BIN directory. To find out where this magical virtual directory maps to on your hard disk, you can use the IIS Manager: navigate to the _VTI_BIN directory and check the properties. The default for the Local Path property is “C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\60\isapi”. So we need to deploy the ASPX page to this directory and of course the corresponding assembly to \BIN in this directory.

The next problem to solve is how to get a hold of the SharePoint web object we want to access. Actually this is quite simple: the GetContextWeb function of the SPControl class can be used to get a SPWeb instance. Based on the Context we’re in, we’ll get the corresponding SPWeb instance.
using Microsoft.SharePoint;
using Microsoft.SharePoint.WebControls;
SPWeb web = SPControl.GetContextWeb(Context);

To construct the contents of the RSS Feed, I’ve used the open source RSS.NET library. This library allows you to build an RSS Feed through a very nice object model. When you’re done you can write the contents to the Response stream:
RssFeed rssFeed = new RssFeed();
rssFeed.Channels.Add(rssChannel);
Response.ContentType = "text/xml";
Response.ExpiresAbsolute = DateTime.MinValue;
rssFeed.Write(Response.OutputStream);

To deploy the APSX page, you only have to copy WhatsNewRss.aspx to the directory that maps to the _VTI_BIN virtual directory (probably C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\60\isapi) and Leadit.SharePoint.Services.dll to the corresponding BIN directory (probably C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\60\isapi\BIN). Now you should be able to browse to the ASPX page through a SharePoint URL, for example http://sharepoint.leadit.be/_vti_bin/WhatsNewRss.aspx. There are three parameters (which you can add to the URL) that you can use to alter the contents of the feed (similar to the properties of the What’s New Web Part):

  • ExcludeLists
    Specify which lists you want to exclude, separated by a semi-colon (;).
    Default value: Web Part Gallery;fpdatasources
  • ListFields
    Specify what field for a specific list should be used as a title.
    Default value: Contacts=Full Name;Links=URL
  • ItemsToDisplay
    Specify how many items to display.
    Default value: 15

Example:
http://localhost:8000/_vti_bin/WhatsNewRss.aspx?ItemsToDisplay=5&ExcludeLists=MyList&ListFields=Contacts=Last Name

The result is an RSS Feed which you can view in any feed reader, for example SharpReader:

As always, please test before you put this thing in production (remember this is V1). Let me know if you have any problems! One final note: for some feed readers it’s necessary to alter the Directory Security for the _VTI_BIN virtual directory. To access the feed from these feed readers you need to allow Basic Authentication:

Downloads:

12 Comments

  • A good approach :)

  • An interesting hickup. I was entering and amending data using the site administrator but all the items thrown up by Rss Feed for SharePoint while specifying the correct change in the correct place at the correct time said that all the changes were done by Esa Viitanen - this is the person who is second on the list of Users for the site and he has only Reader rights!



    (The name and password needed meant that I couldn't use it in Tim's RSS Reader web part but RSSReader 1.0.88.0 was fine with this too.)

  • That is the version I have. I removed the Old Essentials pack and installed the new one. I can not get that RSS Reader to read an RSS feed from whatsnewrss.aspx, but other news Standalone RSS readers will challenge for authentication and read it just fine.

  • If you want to consume the What's New feed to display it on a SharePoint site, I suggest you use the What's New webpart (also in the package). This will prevent authorization problems and gives you the same result.

  • Well Jan, what about putting whats new from one site on another site in the form of RSS webpart? That was the goal.



    Your webparts are nice, I am not saying otherwise, I am just pointing out, your RSS reader will not read your RSS Whats new web service. When one is testing both, esspecially the whatsnewrss.aspx feed it seems logical to just pop that in the already installed Lead It RSS reader webpart to test it out. If it won't do that by design, that is fine, I just wanted to check with this forum to see if anyone else was doing it and maybe I was doing something wrong.

  • The RSSReader webpart then needs some small modifications so it passes along the credentials to the RSS Feed. It's possible, but it will require a few lines of code...

  • Hi Jan, great part. I also am having the issue aggregating the feed from our portal sites, which all have authenticated access. Can you possibly show us how we can include the credentials?

  • When i add a feed url this message appears:

    There was an exception reading the RSS Feed.
    The ServicePointManager does not support proxies of server scheme.

    what´s the trouble, and how can i fix it?

  • Hi Jan, I need some help. I want to ask you a question about Sharepoint designer, how can i write a code for button's(server control) click event like a normal .aspx page. I have added one server control in between one using sharepoint designer. Or is it possible that first i create an .aspx page in MS .net studio and publish on sharepoint site.

  • Lucy! Please call me,Lucy! Please call me

  • Wazzup all

    How I can change avatar in this forum?

  • i can has comment spam? ^_^

Comments have been disabled for this content.