Retrieving query string in sharepoint add-ins - sharepoint

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?

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>');

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.

Related

How to extract lists from Sharepoint which includes the attacthments

Any idea's on how to extract a list (not Library's) from Sharepoint that includes the attachments.
When i extract to excel the attachments column just says YES or NO but no actual copy or link to the attachment.
Any help would be greatly appreciated.
The property you need to use is SPListItem.Attachments (documentation)
Since you haven't provided any code to work from I've had to make a simple example. I would suggest posting the code you're working on in future, you will receive much better replies.
using (var objSite = new SPSite("http://sharepointsite"))
{
using (var web = objSite.OpenWeb())
{
var objlist = web.Lists["Testing List"];
var objItem = objlist.GetItemById(1);
var attachments = objItem.Attachments;
}
}

Get FileDownloadUrl from attachment (Agile PLM)

I've been following the code samples included in Oracle document E15930_01 (Agile PLM Core Web Services User Manual). The samples are in Java, but I've translated what I need to .NET for the project I'm working on.
I can search for an object and return its attachments. I can get all the attachment properties except the one I need, fileDownloadUrl. This field is always blank.
Sample code follows. I thought by setting the property of allFiles to false and downloadUrl to true, I should get a download URL, but I don't. This code returns all the properties for the attachment except the one I want. Any thoughts on what I'm doing wrong?
AttachmentService svc = new AttachmentService();
svc.Credentials = credentials;
AgileGetFileAttachmentRequest[] req2 = InitializeArray<AgileGetFileAttachmentRequest>(1);
AgileFileAttachmentRequestType[] attachments = InitializeArray<AgileFileAttachmentRequestType>(1);
req2[0].classIdentifier = "MyIdentifier";
req2[0].objectNumber = "1234567890";
req2[0].allFiles = false;
req2[0].downloadUrl = true;
req2[0].attachments = attachments;
attachments[0] = new AgileFileAttachmentRequestType();
int rowId = getRowId(tt);
attachments[0].rowId = rowId;
GetFileAttachmentRequestType get = new GetFileAttachmentRequestType();
get.requests = req2;
GetFileAttachmentResponseType resp2 = svc.getFileAttachment(get);
AgileFileAttachmentResponseType[] attchResp = InitializeArray<AgileFileAttachmentResponseType>(1);
attchResp = resp2.responses[0].attachment;
Posting this in case someone else needs to do this or I need to do it later.
I found the data I needed. The download URLs are generated based on XML values in several fields in the database. They're the folder name, filename and FolderVersion on the row you're looking at. You need to parse the XML and retrieve the values to generate the link.
You can get the pattern for the download link through the Get Shortcut button.

Reading Signature lines using OpenXMlSDK

I just started office development and have been trying to read a word 2013 document that holds signature fields in it using open xml sdk
can some one help me how to do that.
using (var document = WordprocessingDocument.Open(#"D:\Temp_Folder\tempfile.docx", false))
{
var docPart = document.MainDocumentPart;
}
I have tried reading word file using ELdos (SBOffice) I can get signature lines but not able to get full details related to Signature Lines like Suggested Signer and Suggested Signer email.
Can some one suggest me which I have to prefer OpenXMLSDK or Eldos(SBOffice) bcz i need to find signature fields and then sign them by custom certificate using Third party Signing Service.
The best way would be to use the OpenXMLSDKTool to open the document and it will show you the code necessary to replicate it. I believe it would be within a shape something like
using (var document = WordprocessingDocument.Open("YourDoc.docx", false)
{
var signature = document.MainDocumentPart.Document.Descendant<DocumentFormat.OpenXML.VML.Office.SignatureLine>().FirstOrDefault();
var suggestedSigner = signature.SuggestedSigner;
var suggestedSignerTitle = signature.SuggestedSigner2;
var suggestedSignerEmail = signature.SuggestedSIgnerEmail;
}
You could get the actual signature image in this same area.

How to Get the Title of a SharePoint List?

I am trying to retrieve a list from SharePoint using the web services. I ran into the problem described in this blog post, i.e. the GetList method apparently expects to be passed the list's title instead of the list's name (even though the parameter is called "listName"). I have the list's name, but I cannot figure out how to get the list's title. Where can I find that?
I'm using the SharePoint in Office 365, which I believe is 2010.
A little over head but try this code. Its just a sample code, you might want to mould it to your logic.
string listName = "MyList";
Lists.Lists listSvc = new Lists.Lists();
listSvc.UseDefaultCredentials = true;
XmlDocument xDoc = new XmlDocument();
xDoc.LoadXml(listSvc.GetListCollection().OuterXml);
XmlNamespaceManager nsmgr = new XmlNamespaceManager(xDoc.NameTable);
nsmgr.AddNamespace("A", "http://schemas.microsoft.com/sharepoint/soap/");
XmlNode requiredList = xDoc.SelectSingleNode("//A:List[contains(#DefaultViewUrl,'" + listName + "')]", nsmgr);
string listTitle = requiredList.Attributes["Title"].Value;
XmlNode list = listSvc.GetList(listTitle);
strListName: Can be either a list name, such as "Documents", or a GUID of the list, with or without curly braces, in the following format:
{318B9E8F-1EF4-4D49-9773-1BD2976772B6}
you may find more info here - the above info is an excerpt from this document

Enterprise Keyword not updating in SharePoint 2010

Any idea how to inject values to the Enterprise Keywords column of a List / Doc Lib Item using code?
Tried the following, it didn't give any error, but that column wouldn't update, while the Title did.
using (var site = new SPSite("http://testweb"))
{
using (var web = site.OpenWeb("testsite1"))
{
var list = web.Lists["testlist1"];
var item = list.AddItem();
item["Title"] = string.Format("Injected from code on {0}", DateTime.Now.ToString());
item["Enterprise Keywords"] = "1;#Opera|4eed0518-9676-4afc-be20-9027b3b69e42";
item.Update();
}
}
In this code, Opera keyword has been added previously, I've checked it against the TaxonomyHiddenList list as well using code to extract the correct ID and IdForTerm (the GUID).
What am I missing here?
To add a taxonomy field value the approach is a little bit different. Please try:
TaxonomyField entKeyword = (TaxonomyField)item.Fields["Enterprise Keywords"];
TaxonomyFieldValue term = new TaxonomyFieldValue("1;#Opera|4eed0518-9676-4afc-be20-9027b3b69e42");
entKeyword.SetFieldValue(item,term);
in stead of:
item["Enterprise Keywords"] = "1;#Opera|4eed0518-9676-4afc-be20-9027b3b69e42";

Resources