Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

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
add comment

2 Answers

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
add comment

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

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
add comment

Your Answer

 
discard

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.