gpt4 book ai didi

c# - 使用 Web 服务将文件上传到 Sharepoint 2013 - 对象引用未设置为对象的实例

转载 作者:行者123 更新时间:2023-11-30 17:02:03 41 4
gpt4 key购买 nike

我正在尝试使用网络服务 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/

41 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com