我正在编写一个 winforms c# 2.0 应用程序,它需要将 XML 文件放入 SharePoint 上的文档库中。
我想使用 WebService 而不是使用对象模型(这里没有要引用的 sharepoint.dll)
我目前正在使用 http://webserver/site/_vti_bin/copy.asmx网络服务。
这是一些代码:
byte[] xmlByteArray;
using (MemoryStream memoryStream = new MemoryStream())
{
xmlDocument.Save(memoryStream);
xmlBytes = memoryStream.ToArray();
}
string[] destinationUrlArray = new string[] {"http://webserver/site/Doclib/UploadedDocument.xml"};
FieldInformation fieldInfo = new FieldInformation();
FieldInformation[] fields = { fieldInfo };
CopyResult[] resultsArray;
using (Copy copyService = new Copy())
{
copyService.Credentials = CredentialCache.DefaultCredentials;
copyService.Url = "http://webserver/site/_vti_bin/copy.asmx";
copyService.Timeout = 600000;
uint documentId = copyService.CopyIntoItems("", destinationUrlArray, fields, xmlByteArray, out resultsArray);
}
当这段代码运行时,我在 resultsArray out 参数中得到一个结果:
DestinationURL: "http://webserver/site/Doclib/UploadedDocument.xml"
ErrorCode: UnKnown
ErrorMessage: "Object reference not set to an instance of an object."
通过搜索,我找到了一些可能的帮助。
Microsoft TechNet -- “copy.asmx copyintoitems 仅在源和目标 url 位于同一 SPWebApplication(网站集)中时才有效。”
Microsoft Social - “你调用的对象是空的 由于 SharePoint 无法识别该特定属性而发生错误。”
这让我相信我的源 url 应该设置为某个东西,但是什么?这源自客户端工作站,没有源 URL。
我们会提供任何帮助。
谢谢你,
基思
最佳答案
我知道这是一个旧话题,但在我寻找同一问题的解决方案时它不断出现。
查看 Steve Curran 在此线程上的回答 http://social.msdn.microsoft.com/Forums/en-SG/sharepointdevelopment/thread/833e38a8-f13c-490d-8ba7-b889b6b25e38 .看起来基本上请求失败,因为无法解析目标 url。
(新 stackflow 用户的限制 - 不能发布多个链接。请参阅我的其余评论)
拍拍
关于c# - 如何使用 WebService 将文件复制到 SharePoint 中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/787610/