作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试使用网络服务 copy.asmx 将文件上传到 Sharepoint 2013
我使用以下方法创建了一个简单的项目:
public bool UploadFile(string file, string destination)
{
bool success = false;
CopySoapClient client = new CopySoapClient();
if (client.ClientCredentials != null)
{
client.ClientCredentials.Windows.ClientCredential = new NetworkCredential("admin", "password", "domain");
}
try
{
client.Open();
string filename = Path.GetFileName(file);
string destinationUrl = destination +@"/"+ filename;
string[] destinationUrls = { destination };
FieldInformation i1 = new FieldInformation { DisplayName = "Title", InternalName = "Title", Type = FieldType.Text, Value = filename};
FieldInformation[] info = { i1 };
CopyResult[] result;
byte[] data = File.ReadAllBytes(file);
uint ret = client.CopyIntoItems(file, destinationUrls, info, data, out result);
if (result != null && result.Length > 0 && result[0].ErrorCode == 0)
success = true;
}
finally
{
if (client.State == System.ServiceModel.CommunicationState.Faulted)
client.Abort();
if (client.State != System.ServiceModel.CommunicationState.Closed)
client.Close();
}
return success;
}
CopySoapClient 是复制服务引用的一部分
http://SPSITE/_vti_bin/copy.asmx
使用以下参数调用该方法:
UploadFile(@"C:\temp\test.txt", "http://SPSITE/sites/Connector/documents/test.txt");
问题是,当程序执行时
uint ret = client.CopyIntoItems(file, destinationUrls, info, data, out result);
Web 服务返回结果“未知错误”,描述为“对象引用未设置到对象的实例。”
我真的不知道我错过了什么。谁能帮我吗?
谢谢。
附言我在 Internet 上提供的示例中注意到人们正在使用 copy.asmx 中的 Copy 类。但我只有 CopySoapClient 类。
最佳答案
您使用了正确的 Web 服务,但在错误的 SharePoint 站点上。尝试在您在此处作为目标库发布的同一个共享点站点上引用此 Web 服务。
关于c# - 使用 Web 服务将文件上传到 Sharepoint 2013 - 对象引用未设置为对象的实例,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20329473/
我是一名优秀的程序员,十分优秀!