SharePointAds TextOnly

Thursday, 6 December 2012

SharePoint Online: Get web full url


Sometimes you need to get full url of current web. following is the short method which will return you full web url.

public string getWebFullUrl( Web web)
{

string webTitle = web.ServerRelativeUrl.Substring(web.ServerRelativeUrl.LastIndexOf( "/" ) + 1);

return web.Context.Url + webTitle + "/" ;

}



Remember web.ServerRelativeUrl will return only relative url, as show in following table:

Site Collection URL
Site URL
web.ServerRelativeUrl
http://MySharepointsite.com
http://MySharepointsite.com
/
http://MySharepointsite.com
http://MySharepointsite.com/site1
/site1
http://MySharepointsite.com
http://MySharepointsite.com/sites/site1
/sites/site1