How do you use the CopyIntoItems method of a SharePoint Copy web service?

I am trying to upload document files to a document library in SharePoint using the CopyIntoItems method of the SharePoint Copy web service.

The code below executes and returns 0 (success). In addition, the CopyResult [] array returns 1 value with the result "Success". However, I cannot find the document anywhere in the library.

I have two questions:

  • Can someone see something wrong with my code or suggest changes?
  • Can anyone suggest me debug this on the server side. I do not have much experience with SharePoint. If I can track what happens through logging or some other server-side method, this can help me figure out what is going on.

Code example:

string[] destinationUrls = { Uri.EscapeDataString("https://someaddress.com/Reports/Temp") }; SPCopyWebService.FieldInformation i1 = new SPCopyWebService.FieldInformation { DisplayName = "Name", InternalName = "Name", Type = SPListTransferSpike1.SPCopyWebService.FieldType.Text, Value = "Test1Name" }; SPCopyWebService.FieldInformation i2 = new SPCopyWebService.FieldInformation { DisplayName = "Title", InternalName = "Title", Type = SPListTransferSpike1.SPCopyWebService.FieldType.Text, Value = "Test1Title" }; SPCopyWebService.FieldInformation[] info = { i1, i2 }; SPCopyWebService.CopyResult[] result; byte[] data = File.ReadAllBytes("C:\\SomePath\\Test1Data.txt"); uint ret = SPCopyNew.CopyIntoItems("", destinationUrls, info, data, out result); 

Change what happened:

I got my code by adding " http: // null " to the SourceUrl field. The nat answer below is likely to work for this reason. Here is the line I changed to make it work.

 // Change uint ret = SPCopyNew.CopyIntoItems("http://null", destinationUrls, info, data, out result); 
+4
source share
3 answers

I think the problem may be trying to set the Name property using webservice. I have had some unsuccessful attempts to do this. Given that "Name" is the name of the document, you can have some success with

  string targetDocName = "Test1Name.txt"; string destinationUrl = Uri.EscapeDataString("https://someaddress.com/Reports/Temp/" + targetDocName); string[] destinationUrls = { destinationUrl }; SPCopyWebService.FieldInformation i1 = new SPCopyWebService.FieldInformation { DisplayName = "Title", InternalName = "Title", Type = SPListTransferSpike1.SPCopyWebService.FieldType.Text, Value = "Test1Title" }; SPCopyWebService.FieldInformation[] info = { i1}; SPCopyWebService.CopyResult[] result; byte[] data = File.ReadAllBytes("C:\\SomePath\\Test1Data.txt"); uint ret = SPCopyNew.CopyIntoItems(destinationUrl, destinationUrls, info, data, out result); 

Note. I used "target" as the "source" property. I don’t know why, but it’s a trick .

+6
source

I didn’t understand very well what you are linking, but if you are trying to upload a file from a local directory to the sharepoint library, I would suggest you create a web client and use uploadata:

Example (VB.NET):

 dim webclient as Webclient webClient.UploadData("http://srvasddress/library/filenameexample.doc", "PUT", filebytes) 

Then you just need to check the file using the web list service, for example:

 listService.CheckInFile("http://srvasddress/library/filenameexample.doc", "description", "1") 

Hope this helps.

EDIT: Remember to provide credentials for the web client, etc.

EDIT 2: update metad fields using this:

 listService.UpdateListItems("Name of the Library, batchquery) 

Here you can find information about creating a batch request: link

+1
source

Sourceurl is used at Sharepoint. This is a link to the "source document". When you hover over an item in your document library, a triangle with a downward cursor will appear on the right. By clicking on it, you will see a menu. Click View Properties. On this page you will see the following: "This item is a copy of http: // null (Go to original position | Unlink)"

Because we use the copy function, Sharepoint tracks the “source element” as part of the document management function.

+1
source

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


All Articles