SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am building a site map using asp:TreeView control, the site map will show a structure consisting of the root site collection, subsites and pages. I am note able to get the url of those pages so i can navigate to them by clicking on a page TreeNode! This component is being built in a custom web part in SharePoint 2010 and all of my site pages are of "Publishing Site" type. I could really use some help :-)

Thnx in advance.

share|improve this question
up vote 0 down vote accepted

this should work...

//pageListItem is an SPListItem from your "Pages" list
if (pageListItem.File != null) {
  string url = pageListItem.File.ServerRelativeUrl;
share|improve this answer
Perfekt! You just solved the problem. Thanx Andrew Petersen & Andrew Adamich i appreciate your help guys. – Eliya Amanoeel Mar 15 '13 at 16:29

you should take your SPListItem - which is a page and get SharePoint "FileRef" field. This should be something similar to:

string[] pageUrlLookUp = list.Items["FileRef"].ToString().Split(new[] { ";#" }, StringSplitOptions.RemoveEmptyEntries);

if (pageUrlLookUp.Length > 1)
   pageUrl = "/" + pageUrlLookUp[1].TrimStart('/');

where list is your page library

Hope it helps,


share|improve this answer
Sir, Thanks for the fast response! Two things: 1. When i run the code, it throws an exception that says "Field with name 'FileRef' was not found." 2. It's list.Items.Fields["FileRef"]... and not list.Items["FileRef"]... SharePoint UI doesn't show that the page file have any field named 'FileRef' which should hold the url to the page. /Eliya – Eliya Amanoeel Mar 15 '13 at 14:53

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.