SharePoint

How to get absolute URLs in SharePoint

Recently I was working on a project where I am building a Site Directory that lists all top-level site collections and their first level sub sites.  In addition, for each listing we wanted to display the site image and some other information.  We encourage our users to change their site image and theme to make their sites their own, and many do.

The site images were displaying fine for those that typed absolute URLs into the Logo URL field; however, for the ones that were using relative URLs, those images were not rendering because they did not exist at that relative path on the site collection that was hosting the site directory.

I did some searching and found this great post that explains exactly how to derive the absolute URL from any relative URL in SharePoint:

Use the SPSite.MakeFullUrl() function:

public string MakeFullUrl(
 string strUrl
)

Simply pass in the string of the relative URL and it returns you the absolute URL.

For example:

string imageUrl = site.MakeFullUrl("/_layouts/images/siteIcon.png");

Returns you the full absolute Url of the site image.

(Visited 459 time, 2 visit today)

3 Comments

Click here to post a comment

About Me

Wendy Neal

Wendy Neal

I am a .NET SharePoint Developer for DMI. I've worked with SharePoint since 2007. I love to share my passion for SharePoint and Office 365 by speaking at various industry and user group events, as well as writing articles for various publications and this blog.   Read More

TwitterCounter for @SharePointWendy
MCSA Office 365
Top 50 SharePoint Blogs

Buy My Book

Archives

  • 2017 (1)
  • 2016 (8)
  • 2015 (23)
  • 2014 (20)
  • 2013 (22)
  • 2012 (15)
  • 2011 (13)