如何使用Sharepoint的默认CopyIntoItems
method通过传入sharepoint用户名和密码从外部web应用程序上传新文件到sharepoint。我不想使用默认凭据,因为我在MVC Web应用程序上使用基于SQL Server的表单身份验证。从外部MVC Web应用程序上传文件到Sharepoint
我已经试过如下:
哪里CopySoapClient
是连接到这个网址的web服务。
http://sharepointaddress/_vti_bin/copy.asmx
代码示例
public static bool UploadSharePointFile(string file, string destination)
{
bool success = false;
CopySoapClient client = new CopySoapClient();
client.ClientCredentials.Windows.ClientCredential = new NetworkCredential("username", "password", "domain");
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);
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;
}
的问题是,我不断收到以下错误:
The HTTP request is unauthorized with client authentication scheme 'Negotiate'. The authentication header received from the server was 'Negotiate,NTLM'.
当我试图把这个在web.config Web服务绑定:
<security mode="Transport">
<transport clientCredentialType="Ntlm" proxyCredentialType="None"
realm="" />
<message clientCredentialType="UserName" algorithmSuite="Default" />
</security>
然后我得到了以下错误:
The provided URI scheme 'http' is invalid; expected 'https'. Parameter name: via