Retrieving a query string in sharepoint add-ins

I am developing a Sharepoint 2013 add-in, and I need to get the query string of the original query.

Users are tied to our email add-ins, and we need to provide some context. The add-in is requested as follows: https://x.sharepoint.com/MyAddIn?p=10

Is it possible to get the p value in my add-in?

+5
source share
2 answers

You can use the following code snippet:

Uri myurl = new Uri(Request.QueryString["SPHostUrl"]); string param1 = HttpUtility.ParseQueryString(myUri.Query).Get("p"); 

or use

 string param1 = Request.QueryString["p"]; 

If you want this via JS, then continue with this.

  function getQueryStringParameter(paramToRetrieve) {        var params;        var strParams;          params = document.URL.split("?")[1].split("&");        strParams = "";        for (var i = 0; i < params.length; i = i + 1) {            var singleParam = params[i].split("=");            if (singleParam[0] == paramToRetrieve) return singleParam[1];        }    }    var sProp = decodeURIComponent(getQueryStringParameter("StringProperty1"));    document.write('Value of StringProperty1 : ' + sProp + '</br>'); 
+2
source

SPHostUrl should definitely not contain your parameter, but you tried another @STORM clause: string param1 = Request.QueryString["p"];

I also think that redirection can be avoided if you add the line of request for the built-in add-ons to the URL that you send to your users as follows: http://<your-app-prefix>.domain.com/<Add In>?SPHostUrl=<host url>&SPAppUrl=<app url>&...&p=10

The add-in that I worked on sends emails to users with links that require context, and this method worked for me.

If this does not work, add the add-in hosted by the hosting hosting or sharepoint. Additional information may be helpful.

+1
source

Source: https://habr.com/ru/post/1240720/


All Articles