Welcome



Hey!!! Welcome to Visit my Blog!!!

Tuesday, March 17, 2009

Find RSS Url for a List or Document Library using Code

RSS Reader webpart which would take the RSS URL of list to render its feeds. Very much same like the out of the box webpart with the exception that it was AJAX enabled. I would post the details of that part on the blog when I am finished.
I thought it would be just a matter of accessing the RssUrl property of SPList object, but to my surprise it was not to be. There is no property such property in the API, so I decided to write my own function for it.
Let’s analyze the RSS URL of a list or a library. Whenever the user clicks on View RSS feed on a library, here is how SharePoint constructs
the URL:

http://server/site/_layouts/listfeed.aspx?List=%7B14206B18%2DF68F%2D479B%2DBC84%2D15EE48D19D7D%7D


Listfeed.aspx is the inbuilt RSS viewer of sharepoint which accepts a parameter which is the GUID of the list. %2D tokens refer to ‘-‘characters which exist inside the GUID. Considering all this, it’s easy to write a function which will return the RSS URL. Here is the code for the same:
private string CreateRssUrl(string rawurl)
{
try
{
Uri url = new Uri(rawurl, UriKind.Absolute);
if (url.GetLeftPart(UriPartial.Path).Contains(“_layouts/listfeed.aspx”))
{
return rawurl;
}
else
{
string rssurl;
using (SPWeb web = new SPSite(rawurl).OpenWeb())
{
SPList list = web.GetListFromUrl(rawurl);
rssurl = web.Url + "/_layouts/listfeed.aspx?list=" + list.ID;
return rssurl;
}
}
}
catch (UriFormatException e)
{
return string.Empty;
}
}

No comments:

Post a Comment

MOSS 2007 Latest Update Videos

Loading...