Download to Sharepoint with FrontPage RPC

I am trying to upload documents with their metadata to sharepoint using the RPC method.
works fine fine, except for some file types like docx, xlsx ..
I do not get any errors or exceptions, they (docx, xlsx.) Are uploaded to sharepoint correctly, but without associated metadata. How can I fix this problem?

Below is the code that I use to download with metadata:

private static bool Upload(string webUrl, string documentName, byte[] bytes, Dictionary<string, object> metaInfo, NetworkCredential netAccess, out string result) { string putOption = "overwrite,createdir,migrationsemantics"; // see http://msdn2.microsoft.com/en-us/library/ms455325.aspx string comment = null; bool keepCheckedOut = false; string method = "method=put+document%3a12.0.4518.1016&service_name=%2f&document=[document_name={0};meta_info=[{1}]]&put_option={2}&comment={3}&keep_checked_out={4}\n"; method = String.Format(method, documentName, EncodeMetaInfo(metaInfo), putOption, HttpUtility.UrlEncode(comment), keepCheckedOut.ToString().ToLower()); List<byte> data = new List<byte>(); data.AddRange(Encoding.UTF8.GetBytes(method)); data.AddRange(bytes); try { using (WebClient webClient = new WebClient()) { webClient.Credentials = netAccess; webClient.Headers.Add("Content-Type", "application/x-vermeer-urlencoded"); webClient.Headers.Add("X-Vermeer-Content-Type", "application/x-vermeer-urlencoded"); result = Encoding.UTF8.GetString(webClient.UploadData(webUrl + "/_vti_bin/_vti_aut/author.dll", "POST", data.ToArray())); if (result.IndexOf("\n<p>message=successfully") < 0) throw new Exception(result); } } catch (Exception ex) { result = ex.Message; return false; } return true; } 
+4
source share
3 answers

This is old, but metadata has not been set for office files due to the promotion of properties in SharePoint. If you create your own web service, you can disable this when you add the document. To use FrontPage rpc, just set the metadata again after the first call to "PUT" -mthode, you will get a different version, but in the second case metadata is used.

+3
source

I'm not sure exactly what the problem is with your code, but there is the same code that uploads files to Sharepoint 2007 via RPC calls to this blog that you can try.

0
source

Gaby, I have the same behavior for docx and xlsx files.

After loading the document, if the file is of type docx or xlsx, I call sp webservice to update the metadata.

This is the code immediately after a successful file upload:

  int extlength = 0; extlength = documentName.Length - documentName.LastIndexOf(".") - 1; string docext = documentName.Substring(documentName.LastIndexOf(".") + 1, extlength); if (docext == "xlsx" || docext == "docx") { string doclookupname = metaInfo["PermitApplicationID"].ToString() + "_" + metaInfo["Title"].ToString(); UpdateMetaData("Shared Documents", "1", doclookupname, "PermitApplicationID", metaInfo["PermitApplicationID"].ToString()); UpdateMetaData("Shared Documents", "1", doclookupname, "DocumentCategories", metaInfo["DocumentCategories"].ToString()); UpdateMetaData("Shared Documents", "1", doclookupname, "Title", metaInfo["Title"].ToString()); } 

This is the function that the above code calls to update metadata using the sp list service. I call this function for each metadata value that I want to update.

  private static void UpdateMetaData(string strListName, string rowLimit, string strDocTitle, string FieldName, string NewValue) { Lists_WinAuth.Lists li = new Lists_WinAuth.Lists(); li.Credentials = new NetworkCredential("yourUserID", "YourPwd", "YourDomain"); XmlDocument xmlDoc = new System.Xml.XmlDocument(); /////////get id XmlNode ndQuery = xmlDoc.CreateNode(XmlNodeType.Element, "Query", ""); XmlNode ndViewFields = xmlDoc.CreateNode(XmlNodeType.Element, "ViewFields", ""); XmlNode ndQueryOptions = xmlDoc.CreateNode(XmlNodeType.Element, "QueryOptions", ""); ndQueryOptions.InnerXml = "<IncludeMandatoryColumns>FALSE</IncludeMandatoryColumns>" + "<DateInUtc>TRUE</DateInUtc>"; ndViewFields.InnerXml = "<FieldRef Name='ID' /> "; ndQuery.InnerXml = "<Where>" + "<Eq>" + "<FieldRef Name='FileLeafRef' />" + "<Value Type='Text'>" + strDocTitle + "</Value>" + "</Eq>" + "</Where>"; XmlNode ndListItems = li.GetListItems(strListName, "", ndQuery, ndViewFields, rowLimit, ndQueryOptions, null); string strDocID = ndListItems.ChildNodes[1].ChildNodes[1].Attributes[0].Value.ToString(); //////////update string strBatch = "<Method ID='1' Cmd='Update'>" + "<Field Name='ID'>" + strDocID + "</Field>" + "<Field Name='" + FieldName + "'>" + NewValue + "</Field></Method>"; System.Xml.XmlElement elBatch = xmlDoc.CreateElement("Batch"); elBatch.SetAttribute("OnError", "Continue"); elBatch.InnerXml = strBatch; try { XmlNode ndReturn = li.UpdateListItems("Shared Documents", elBatch); } catch (Exception ex) { throw; } return; } 
0
source

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


All Articles