0

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.

2 Answers 2

0

this should work...

//pageListItem is an SPListItem from your "Pages" list
if (pageListItem.File != null) {
  string url = pageListItem.File.ServerRelativeUrl;
}
1
  • Perfekt! You just solved the problem. Thanx Andrew Petersen & Andrew Adamich i appreciate your help guys. Mar 15, 2013 at 16:29
0

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,

Andrew

1
  • 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 Mar 15, 2013 at 14:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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