Getting Absolute URLs in SharePoint

This is a bit of a reminder for myself, but quite a lot of the URLs you deal with in SharePoint development are relative – that is, something like an SPList.DefaultViewURL might be:


That’s fine … but sometimes you need a full absolute URL. For example, you might be sending out an email with a hyperlink in it – a relative URL ain’t going to cut it.

Fortunately, there is a very useful function – SPSite.MakeFullUrl() :

Returns the full URL for the specified server-relative URL.

That’s great – but it raises some questions. What about Alternate Access Maps? What URL would be returned? Well, predictably, the URL used in the SPSite Constructor in the first place. Mostly, they either accept a URL (which defines a zone), or they accept a GUID and an SPUrlZone value. There is a constructor that just accepts a GUID – which will then use the default zone. Similarly, the constructor accepting a GUID and SPUserToken also uses the Default Zone.

(If you open it up in reflector, you can see it just calling a private constructor passing the SPUrlZone.Default value).

Getting Absolute URLs in SharePoint

3 thoughts on “Getting Absolute URLs in SharePoint

  1. I would guess it’s that the MakeFullUrl relies on the ‘relative’ url being relative to the Site Collection root, rather than the server root. What object are you gettig your relative URL from? Most objects – SPFile, SPList, etc. – have multiple properties for getting these different URLs relative to the server, site collection, or site.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.