将文件上载到Sharepoint返回413请求实体太大

本文关键字:请求 实体 返回 文件 上载 Sharepoint | 更新日期: 2023-09-27 18:23:47

我收到一个错误

尝试发出请求时发生Web异常。远程服务器返回错误:(413)请求实体太大。:

当尝试从ASP.Net Web应用程序将文件上载到Sharepoint网站时。用户添加通过ASP.Net文件上载控件选择一个文件,下面的代码将其上载到Sharepoint。我试图上传的文件大约是250k(即不是很大)。

代码如下:

public string SharepointWebClientSOAPPost(Uri webService, string SOAPAction, string contentType, string postData, NetworkCredential networkCredential = null, string webProxy = "", NetworkCredential webserviceCredentials = null)
{
    try
    {
        using (WebClient client = new WebClient())
        {
            if (string.IsNullOrEmpty(webProxy) && webserviceCredentials != null)
            {
                client.Proxy = new WebProxy(new Uri(webProxy));
                client.Proxy.Credentials = webserviceCredentials;
            }
            if (networkCredential != null)
            {
               client.Credentials = networkCredential;
            }
            client.Headers.Add(HttpRequestHeader.ContentType, contentType);
            client.Headers.Add("SOAPAction", SOAPAction);
            // Apply ASCII Encoding to obtain the string as a byte array.
            var byteArray = Encoding.ASCII.GetBytes(postData);
            // Upload the input string using the HTTP 1.0 POST method.
            var responseArray = client.UploadData(webService, "POST", byteArray);
            // Decode and return the response.
            var response = Encoding.ASCII.GetString(responseArray);
            return response; 
        }
    }
    catch(Exception ex)
    {
        //etc.
    }
}

我在web.config 中有以下集合

<httpRuntime maxRequestLength="1024000" />

如果我使用一个只有几k的文本文件,它会很好地工作,所以我认为基本思想是正确的(SOAP消息的格式是正确的,URL是正确的)。但是,SP站点的负责人告诉我,它已配置为接受大小高达50MB的文档。

有什么想法可以让我从哪里开始寻找问题吗?

将文件上载到Sharepoint返回413请求实体太大

您的代码使用WCF上传文件,而不是ASP.NET。为此,您必须配置web.configmaxReceivedMessageSize,如下所示:

<system.serviceModel>
  <bindings>
    <basicHttpBinding>
      <binding maxReceivedMessageSize="10485760">
      </binding>
    </basicHttpBinding>
  </bindings>  
</system.serviceModel>