Showing posts with label FileRef. Show all posts
Showing posts with label FileRef. Show all posts

Monday, April 28, 2008

Link to an item when running SPSiteDataQuery

Many a times we will need to run SPSiteDataQuery on a list to get the results from a sitecollection. Now once we have retreived the results from the query we need to get the url of each item. There is a hidden column "EncodedAbsUrl" which consists of complete URL to an Item. For some reason accessing this column doesn't give us the complete URL that we need (I don't know why). But there is another trick to get the URL of an item. There is another hidden column "FileRef" in each list. This column data has got the URL with the item ID concatenated to it, something like this:

row["FileRef"] = 1;#Popular Wiki/How To Use This Wiki Library.aspx

**row is from the datatable returned when you run web.GetSiteData(query) and query is the constructed SPSiteDataQuery.

We can retreive the URL part from it and construct the complete link from the root site. Something like this:

string url = row["FileRef"].ToString().Substring(row["FileRef"].ToString().IndexOf("#") + 1);

string finalUrl = site.MakeFullUrl(url);

You can read more about MakeFullUrl() method here msdn
Dogpile
Powered By Blogger