Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Retrieving query string in sharepoint add-ins

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?

like image 815
Tommy Jakobsen Avatar asked Jan 15 '16 19:01

Tommy Jakobsen


People also ask

Where is query string stored?

The information within a query string is passed to your website and stored in the server log files where it can be saved as embedded data and used for a variety of applications.

Can you query in SharePoint?

SharePoint search supports Keyword Query Language (KQL) and FAST Query Language (FQL) search syntax for building search queries. KQL is the default query language for building search queries. Using KQL, you specify the search terms or property restrictions that are passed to the SharePoint search service.

What is CAML Query in SharePoint?

CAML is an XML-based language that is used in Microsoft SharePoint Foundation to define the fields and views that are used in sites and lists.


1 Answers

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>');
like image 86
STORM Avatar answered Oct 29 '22 09:10

STORM