Domanda

I am currently developing a SharePoint visual web part farm solution. I'm having trouble determining how without hardcoding a link to get from http://sharetest/sites/Dev/_layouts/15/HelpDesk/EditWorkOrder.aspx?2 to http://sharetest/sites/Dev/SitePages/Tickets.aspx. I shouldn't have to type in /sites/dev as when I move it to the live SharePoint it will be wrong.

I have tried many variations and can't seem to find one that works.

//Response.Redirect("http://sharetest/sites/Dev/SitePages/Tickets.aspx"); Response.Redirect("~/SitePages/Tickets.aspx");

È stato utile?

Soluzione

You can get web absolute url and concatenate it with "/SitePages/Tickets.aspx".

On Client side:

<script type="text/javascript">
var YOUR_URL = _spPageContextInfo.webAbsoluteUrl + "/SitePages/Tickets.aspx";
Response.Redirect(YOUR_URL);
</script>

On Server side:

SPWeb curWeb = SPContext.Current.Web;
string YOUR_URL = curWeb.Url + "/SitePages/Tickets.aspx";
Response.Redirect(YOUR_URL);
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a sharepoint.stackexchange
scroll top