2009-06-12 49 views
4

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

下面的代码执行并返回0(成功)。此外,CopyResult []数组返回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); 

编辑得到的东西的工作:

我得到了我的代码加入 “http://null” 到SourceUrl领域工作。 Nat的答案可能会出于这个原因。这是我为改变它而改变的一行。

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

应该不是使用Uri.EscapeUriString而不是Uri.EscapeDataString? – 2010-02-28 13:08:31

+0

Uri.EscapeUriString对我更好。 – 2013-12-19 17:25:39

回答

6

我认为这个问题可能是在尝试使用web服务设置“名称”属性。我做了一些失败。 鉴于“名称”为文档的名称,你可能有一些成功的

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

注:我已经使用了“目标”的“源”属性。 Don't quite know why, but it does the trick

1

我不很了解你绑做什么,但如果你想从本地目录中的文件上传至SharePoint库,我建议你创建一个Web客户端和使用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

+0

+1 - 这是一个好方法。但是,我想同时设置与该文件关联的元数据。 – 2009-06-15 14:59:50

1

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

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

相关问题