SharePoint Get Current Web URL

How to get SharePoint site current URL ?

We can get SharePoint Current web url in Server-Side as well as in Client side.

Server Side:

 As we all know current web url can be accessed in server side by web object as below.

SPContext.Current.Web.Url

Client Side:

In client side , we can achieve this by using SPServices .

Here is how to achieve this:
Include SPServices js file in your page.
Now you can access the url this way:
var thisWebUrl = $().SPServices.SPGetCurrentSite();
But there is a bug in recent versions of SPServices , where the above method will return only "/".
But in SharePoint 2013, we  can access web url as below as well :
var thisWebUrl = _spPageContextInfo.webAbsoluteUrl; (web url)
var thisSiteUrl = _spPageContextInfo.siteAbsoluteUrl; (site url)
Enjoy coding :)

Comments

Popular posts from this blog

SharePoint Online (O365) OAuth Authentication | Authorizing REST API calls against SharePoint Online Site | Get Access token from SharePoint Online | Set up OAuth for SharePoint Online Office 365

SharePoint 2013 REST API Reference

Simple Risk Assessment Matrix table with resultant risk calculation

Kendo UI (Core JavaScript) grid Server Paging, Server Sorting and Server Filtering with Dynamic SQL queries

Sharepoint- Using an Image From formatmap32x32.png in a Ribbon Control