如何使用SharePoint Copy Web服务的CopyIntoItems方法?

时间:2009-06-12 16:16:29

标签: c# .net web-services sharepoint

我正在尝试使用SharePoint Copy Web服务的CopyIntoItems方法将文档文件加载到SharePoint中的文档库中。

下面的代码执行并返回0(成功)。此外,CopyResult []数组返回1个带有“Success”结果的值。但是,我无法在库中的任何位置找到该文档。

我有两个问题:

  1. 任何人都可以看到我的代码有什么问题或建议更改吗?
  2. 任何人都可以建议我如何在服务器端调试它。我没有大量的SharePoint经验。如果我可以通过日志记录或服务器端的其他方法跟踪正在发生的事情,它可以帮助我弄清楚发生了什么。
  3. 代码示例:

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

    编辑让事情有效:

    我通过在SourceUrl字段中添加“http://null”来使我的代码正常工作。 Nat的答案可能就是出于这个原因。这是我为改变它而改变的一条线。

    // Change
    uint ret = SPCopyNew.CopyIntoItems("http://null", destinationUrls, info, data, out result);
    

3 个答案:

答案 0 :(得分:6)

我认为问题可能在于尝试使用webservice设置“Name”属性。我做了一些失败。 鉴于“名称”是文档的名称,您可以使用

取得一些成功
    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);

注意:我使用“target”作为“source”属性。 Don't quite know why, but it does the trick

答案 1 :(得分:1)

我不太清楚你要做什么,但是如果你试图将文件从本地目录上传到sharepoint库,我建议你创建一个webclient并使用uploadata:

示例(VB.NET):

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

然后您只需使用列表Web服务签入文件,例如:

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

希望它有所帮助。

编辑:不要忘记为Web客户端等设置凭据

编辑2:使用以下方法更新metada字段:

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

您可以在此处找到有关构建批量查询的信息:link

答案 2 :(得分:1)

Sourceurl用于Sharepoint。它是返回“源文档”的链接。在文档库中时,将鼠标悬停在项目上方,右侧会出现一个向下指向的三角形。点击它,会弹出一个菜单。单击“查看属性”选项。在此页面上,您将看到以下“此项目是http://null的副本(转到源项目|取消链接)”

因为我们正在使用复制功能,Sharepoint会跟踪“源项目”作为文档管理功能的一部分。