There are times when you want to dynamically construct a SharePoint site relative Urls e.g. if you are calling a SharePoint webservice from JQuery etc. then you will need to call it in context of your required site.
Most people try to slice and dice the URL of the current page and try to find the SharePoint site from it. This is not a very clean way of doing it.
The more easy and clean way is the way SharePoint itself does which is using the JavaScript variable called L_Menu_BaseUrl
This variable holds the relative url of current site.
So for example, if you want to call Lists.asmx for
http://yourintranet/sites/Finance/ then
L_Menu_BaseUrl + ‘/_vti_bin/Lists.asmx’ will give you the required url for web service.
Hi thr, thanxc a lot for this blog …….. This is what I was looking for.
This is useful – does it apply in code behind? I can’t seem to find the relative url for use within a menu tag :/
Thank you very much, useful one 🙂