使用Sharepoint提供的Web服务(CopyIntoItems)
使用Sharepoint webservice的jQuery库
醇>
搜索网页后,我认为jQuery部分不起作用(你可以纠正我)。
我正在寻找一种获取用户名/密码并将pdf文件上传到Sharepoint服务器的方法。以下是我尝试上传但最终错误的C#代码
public bool UploadFile(string file, string destination)
{
bool success = false;
CopySoapClient client = new CopySoapClient();
if (client.ClientCredentials != null)
client.ClientCredentials.Windows.AllowedImpersonationLevel = System.Security.Principal.TokenImpersonationLevel.Impersonation;
try
{
client.Open();
string filename = Path.GetFileName(file);
string destinationUrl = destination + filename;
string[] destinationUrls = { destinationUrl };
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(filename, destinationUrls, info, data, out result);
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;
}
我正在调用上面的函数
UploadFile(@"C:\temp\uploadFile.txt", "http://spf-03:300/demo/Dokumente").ToString();
我得到的错误:
错误代码:目标无效
错误消息:必须在包含目标URL的同一域上调用服务方法“Copy”。