Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

I am attempting to load document files into a document library in SharePoint using the CopyIntoItems method of the SharePoint Copy web service.

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

I have two questions:

  1. Can anyone see anything wrong with my code or suggest changes?
  2. Can anyone suggest how I could debug this on the server side. I don't have a tremendous amount of experience with SharePoint. If I can track what is going on through logging or some other method on the server side it may help me figure out what is going on.

Code Sample:

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

Edit that got things working:

I got my code working by adding "http://null" to the SourceUrl field. Nat's answer below would probably work for that reason. Here is the line I changed to get it working.

// Change
uint ret = SPCopyNew.CopyIntoItems("http://null", destinationUrls, info, data, out result);
like image 418
Matt Spradley Avatar asked Feb 28 '23 15:02

Matt Spradley


2 Answers

I think the issue may be in trying to set the "Name" property using the webservice. I have had some fail doing that. Given the "Name" is the name of the document, you may 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 have used the "target" as the "source" property. Don't quite know why, but it does the trick.

like image 126
Nat Avatar answered May 01 '23 13:05

Nat


I didn't understand very well what you're tying to do, but if you're trying to upload a file from a local directory into a sharepoint library, i would suggest you create a webclient and use uploadata:

Example (VB.NET):

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

Then you just have to check in the file using the lists web service, something like:

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

Hope it was of some help.

EDIT: Don't forget to set credentials for the web client, etc.

EDIT 2: Update metada fields using this:

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

You can find info on building batch query's in here: link

like image 38
v3ga Avatar answered May 01 '23 11:05

v3ga