Need help with relative path from application page to sitepage
-
16-01-2021 - |
Pregunta
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");
Solución
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);
Licenciado bajo: CC-BY-SA con atribución
No afiliado a sharepoint.stackexchange