C# – How to use the CopyIntoItems method of the SharePoint Copy web service

cnetsharepointweb services

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

Best Answer

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.