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

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

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

我有两个问题:

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

代码示例:

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

我认为问题可能在于尝试使用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); 

注意:我使用“目标”作为“源”属性。 不知道为什么,但它确实有把戏 。

我不太清楚你要做什么,但是如果你试图将文件从本地目录上传到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

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

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