C# 您如何使用 SharePoint Copy Web 服务的 CopyIntoItems 方法?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/987581/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How do you use the CopyIntoItems method of the SharePoint Copy web service?
提问by Matt Spradley
I am attempting to load document files into a document library in SharePoint using the CopyIntoItems method of the SharePoint Copy web service.
我正在尝试使用 SharePoint Copy Web 服务的 CopyIntoItems 方法将文档文件加载到 SharePoint 中的文档库中。
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.
下面的代码执行并返回 0(成功)。此外, CopyResult[] 数组返回 1 个具有“成功”结果的值。但是,我在图书馆的任何地方都找不到该文档。
I have two questions:
我有两个问题:
- Can anyone see anything wrong with my code or suggest changes?
- 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.
- 任何人都可以看到我的代码有什么问题或建议更改吗?
- 谁能建议我如何在服务器端调试它。我对 SharePoint 的经验并不丰富。如果我可以通过日志记录或服务器端的其他方法跟踪正在发生的事情,它可能会帮助我弄清楚发生了什么。
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.
我通过向SourceUrl 字段添加“ http://null”来使我的代码工作。出于这个原因,Nat 在下面的回答可能会起作用。这是我为使其工作而更改的行。
// Change
uint ret = SPCopyNew.CopyIntoItems("http://null", destinationUrls, info, data, out result);
采纳答案by Nat
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.
注意:我使用了“目标”作为“源”属性。不太清楚为什么,但它确实有效。
回答by v3ga
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:
我不太明白您要做什么,但是如果您尝试将文件从本地目录上传到共享点库,我建议您创建一个网络客户端并使用uploadata:
Example (VB.NET):
示例(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:
然后,您只需使用列表 Web 服务检入文件,例如:
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.
编辑:不要忘记为 Web 客户端等设置凭据。
EDIT 2: Update metada fields using this:
编辑 2:使用此更新元数据字段:
listService.UpdateListItems("Name of the Library, batchquery)
You can find info on building batch query's in here: link
您可以在此处找到有关构建批处理查询的信息:链接
回答by Lewis
The sourceurl is used in Sharepoint. It is a link back to the "Source Document." When in your document library, hover over the item, to the right appears a down pointing triangle. Clicking on it, brings up a menu. Click on the "View Properties" Option. On this page you will see the following "This item is a copy of http://null( Go To Source Item | Unlink )"
在 Sharepoint 中使用 sourceurl。它是指向“源文档”的链接。在您的文档库中,将鼠标悬停在该项目上时,右侧会出现一个向下的三角形。点击它,会出现一个菜单。单击“查看属性”选项。在此页面上,您将看到以下内容“此项目是http://null的副本(转到源项目 | 取消链接)”
Because we are using the Copy function Sharepoint is keeping track of the "Source item" as part of the Document Management feature.
因为我们正在使用复制功能,Sharepoint 将跟踪“源项目”作为文档管理功能的一部分。