【问题标题】:Upload file to Sharepoint from External MVC Web Application从外部 MVC Web 应用程序将文件上传到 Sharepoint
【发布时间】:2013-08-01 01:06:07
【问题描述】:

我如何使用 Sharepoint 的默认 CopyIntoItems method 通过传入共享点用户名和密码从外部 Web 应用程序将新文件上传到共享点。我不想使用默认凭据,因为我在 MVC Web 应用程序上使用基于 SQL Server 的表单身份验证。

我尝试了以下方法:

CopySoapClient 是连接到此 url 的网络服务。

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;
}

问题是我不断收到以下错误:

HTTP 请求未通过客户端身份验证方案“协商”进行授权。从服务器收到的身份验证标头是“Negotiate,NTLM”。

当我尝试将它放在 web.config 中的 web 服务绑定中时:

<security mode="Transport">
    <transport clientCredentialType="Ntlm" proxyCredentialType="None"
      realm="" />
    <message clientCredentialType="UserName" algorithmSuite="Default" />
</security>

然后我得到以下错误:

提供的 URI 方案“http”无效;预期的“https”。参数名称:via

【问题讨论】:

    标签: c# asp.net-mvc sharepoint file-upload


    【解决方案1】:

    我想通了。我需要做的就是将 web.config 中的安全模式更改为

    TransportCredentialOnly

    <security mode="TransportCredentialOnly">
        <transport clientCredentialType="Ntlm" proxyCredentialType="None"
          realm="" />
        <message clientCredentialType="UserName" algorithmSuite="Default" />
    </security>
    

    【讨论】:

      猜你喜欢
      • 2010-09-21
      • 2013-06-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-06-06
      相关资源
      最近更新 更多