Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SharePoint get the full URL of the current page in code behind

Tags:

In SharePoint how do you get the url of the page you are on from the code behind? e.g. with the blah.aspx page included...

SPContext.Current.Web.Url gives http://vm/en/

I need it with http://vm/en/Pages/blah.aspx

like image 851
raklos Avatar asked Oct 09 '09 14:10

raklos


People also ask

How do I find the current URL in SharePoint?

Select Get Link from the menu. 2. Click the SharePoint menu option and select Copy to copy the URL.

What is SharePoint absolute URL?

Types of URLs in SharePoint An absolute URL specifies a full path and begins with a protocol. For example, http:// domain_or_server/[ sites/ ] Web_Site/ Lists / List_Title/ AllItems. aspx . A domain-relative URL is based on the domain (which might be the name of a server) address and always begins with a forward slash.

What is Server relative URL SharePoint?

In SharePoint (among other things), URLs can be of two different types, absolute and relative. The absolute URL for an object is the full path direct to that object, where the relative URL is an abbreviated path that combines the base URL and the current location.

What is service URL in SharePoint?

URL for a SharePoint Server Site or Subsite In the URL, the site name appears immediately after the server name., for example, https://*servername/site* or https://*servername/site/subsite* .


2 Answers

You can still get the HttpContext and then use HttpContext.Current.Request.Url

SPContext.Current.Web is the SPWeb surrounding the page you're on, and thus its URL is the URL of the Web, not the page.

like image 95
Yuliy Avatar answered Sep 20 '22 01:09

Yuliy


Try: SPContext.Current.File.Url

You could also use HttpContext.Current.Request.Url

like image 44
Alex Angas Avatar answered Sep 20 '22 01:09

Alex Angas