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.
That is really very good article. I am glad to know. Thanks!
SharePoint always drives me crazy to know something more about it. This is quite true, I followed this method and the result was in my hand. Now the absolute URLs works fine with everything rather than the relative URLs.
Gratitude for sharing your thoughts about How to get absolute URLs in SharePoint . Maintain up the excellent job in posting very fine topics. I am satisfied to find so many magnificent tips here in the blog post,