Get RSS Url for a list or Document Library Programmatically

I developed an 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.

idea came to me that wouldn’t it be nice to also enable users to just
give the list URL rather than RSS URL since would reduce the few steps
on the user’s side. 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:


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 MakeRssUrl(string rawurl)




Uri url = new Uri(rawurl, UriKind.Absolute);

if (url.GetLeftPart(UriPartial.Path).Contains(“_layouts/listfeed.aspx”))


return rawurl;




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;



code is pretty self explanatory. The argument to function is list URL
or RSS url. We first check if the URL is RSS URL itself, and if it is
we just return. Otherwise, if it’s a list URL, we create a SPList
instance, grap the GUID and contatenate it with the site URL and

that the function does not validate if the given URL was actually a
valid list URL or not. The exception handling for that case should be
left to the caller of the function.

Comments (3)
  1. Parag says:

    Hi Madhur,

    We are deploying a custom list via a feature and want to control what list columns are shown in the RSS feed.

    In general, how are the RSS columns decided for a list by default? Where are they stored?

    Is there anyway to control this via schema declaration? Even with a custom RssView.aspx page, the list "RSS Settings" link shows some other column selection.

    If not, what other options would you recommend. Note that the list is deployed to multiple sites and sub sites. Could this be possible via the API?

    I know these are a lot of questions, but just a tough time finding anything around this topic.


  2. Anne Ahira says:

    by the way Mahdur, I am not a tech person, but I have one quick question, is that possible to get full text from a source using its RSS feed?

  3. Madhur Ahuja says:

    Hi Anne

    Sure its possible. But I am confused what do you mean by full text ? If you could clarify, I can give you the pointer on how to do it.

Comments are closed.

Skip to main content