Reputation: 2361
I'm developing a Sharepoint 2013 Add-in, and I need to retrieve the query string of the original request.
Users are linked to our add-ins from emails and we need to provide some context. The add-in is requested like this: https://x.sharepoint.com/MyAddIn?p=10
Is it possible to retrieve the value of p in my add-in?
Upvotes: 6
Views: 1273
Reputation: 26
The SPHostUrl definitely shouldn't contain your parameter, but have you tried @STORM 's other suggestion:
string param1 = Request.QueryString["p"];
Also I think it may be possible to avoid the redirect if you append the built-in add-in query string to the URL you are sending your users like so:
http://<your-app-prefix>.domain.com/<Add In>?SPHostUrl=<host url>&SPAppUrl=<app url>&...&p=10
The add-in's that I've worked on send user's emails with links that require context as well and this method has worked for me.
If this doesn't work, is your add-in a provider-hosted or sharepoint-hosted add-in. This extra info may be helpful.
Upvotes: 1
Reputation: 4331
You could 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 to this via JS, then go on 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>');
Upvotes: 2