您如何使用 SharePoint Copy Web 服务的 CopyIntoItems 方法? [英] How do you use the CopyIntoItems method of the SharePoint Copy web service?
问题描述
我正在尝试使用 SharePoint Copy Web 服务的 CopyIntoItems 方法将文档文件加载到 SharePoint 中的文档库中.
I am attempting to load document files into a document library in SharePoint using the CopyIntoItems method of the SharePoint Copy web service.
下面的代码执行并返回0(成功).此外, CopyResult[] 数组返回 1 个具有成功"结果的值.但是,我在图书馆的任何地方都找不到该文档.
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.
我有两个问题:
- 有人能看到我的代码有什么问题或提出更改建议吗?
- 谁能建议我如何在服务器端调试它.我对 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 在下面的回答可能会起作用.这是我为使其正常工作而更改的行.
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);
推荐答案
我认为问题可能在于尝试使用网络服务设置名称"属性.我在这样做时遇到了一些失败.鉴于名称"是文档的名称,您可能会成功
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.
这篇关于您如何使用 SharePoint Copy Web 服务的 CopyIntoItems 方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!