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

When I use SPContext.Current.Site.Url it returns "http://servername"

I need the full homepage URL which is "http://servername/SitePages/Home.aspx"

Does anyone know how to get this programmatically?

share|improve this question

3 Answers 3

up vote 5 down vote accepted

Try

SPContext.Current.Site.RootWeb.RootFolder.WelcomePage

share|improve this answer

as an addition, in general, if you are inside a page and you want to get full path you always can use:

SPContext.Current.Web.Url + "/" + SPContext.Current.File.Url
share|improve this answer

To get full url (absolute), you have to :

SPWeb parentWeb=SPContext.Current.Site.RootWeb;
string strFullHomePageUrl= parentWeb.Url+ "/"+ parentWeb.RootFolder.WelcomePage;
share|improve this answer
    
You can also use SPUrlUtility to build the URL: SPUrlUtility.CombineUrl(parentWeb.Url, parentWeb.RootFolder.WelcomePage) –  Rachel Jul 21 at 8:25

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.