0

How to get the SharePoint site secured URL(https) ,present I am using this :

SPWeb web= web app.Sites[0].RootWeb;

string example = web.URl+"/sites/pages/...../....aspx";
1

You can get your Web URL by using the piece of code below :

string example = SPContext.Current.Web.Url+"/pages/...../....aspx";

or

using (SPSite site = new SPSite(SPContext.Current.Web.Url))
{
      using(SPWeb web = site.OpenWeb())
      {
         string example = web.Url+"/pages/...../....aspx";
      }
}

NOTE : SPContext.Current.Web.Url gives the Url of the site whether root or inner site

  • thank you but i am getting null exception in timerjob – karthik Sep 18 '17 at 19:06
  • I am trying to get the https link of the particular page and include that in email and send to the users using the timer job every week, like weekly updates – karthik Sep 18 '17 at 19:14
  • Yes you will get null you do not have access to Context because the timer job does not run within a context. – Youssef Moumen El idrissi Sep 18 '17 at 19:28
  • Try this code to get url in the Execute() methode : SPWebApplication webapp = this.Parent as SPWebApplication; string example = webapp.Sites[0].RootWeb.Url; – Youssef Moumen El idrissi Sep 18 '17 at 19:31
  • SPWebApplication webapp = this.Parent as SPWebApplication; string example = webapp.Sites[0].RootWeb; string securedModeURL =web.Url.Replace("http","https") ; wrote this and solved my problem able to get the secured link (https) ,thankyou for your help – karthik Sep 19 '17 at 12:39
0
SPWebApplication webapp = this.Parent as SPWebApplication;                   
string example = webapp.Sites[0].RootWeb; //from this you will get the http link                                    
   string securedModeURL =web.Url.Replace("http","https") ; 

//here you will change https , you will get the secured link of the site i.e., "https://example.com"

0

You can get the HttpContext and then use HttpContext.Current.Request.Url to get the URL of current page.

Using SPContext.Current.Web you can get the SPWeb surrounding the page you're on, and thus its URL will be the URL of the Web, not the current page you are on.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.