0

We have an windows application that uploads files to SharePoint 2010 via client object model. We have raised the upload limit as in the following article: http://msdn.microsoft.com/en-us/library/ff599489.aspx.

We have done this via powershell:

$ws = [Microsoft.SharePoint.Administration.SPWebService]::ContentService

$ws.ClientRequestServiceSettings.MaxReceivedMessageSize = 78643200  #75MB

$ws.Update()

This works fine for files up to approximately 40 MB. After that we receive the following exception:

The remote server returned an error: (401) Unauthorized.

System.Net.WebExceptionStatus.ProtocolError

at System.Net.HttpWebRequest.GetResponse() at Microsoft.SharePoint.Client.SPWebRequestExecutor.Execute() at Microsoft.SharePoint.Client.ClientRequest.ExecuteQueryToServer(ChunkStringBuilder sb) at Microsoft.SharePoint.Client.ClientRequest.ExecuteQuery()
at Microsoft.SharePoint.Client.ClientRuntimeContext.ExecuteQuery()
at Microsoft.SharePoint.Client.ClientContext.ExecuteQuery() at UploadClient.FileUpload.Service.SharePointService.CreateFile

We have also tried increasing the upload size via:

    public static void IncreaseUploadSize()
    {
        SPWebService contentService = SPWebService.ContentService;

        /* Must set this to -1, else, the MaxReceivedMessageSize value for
        SPWebService.ContentService.WcfServiceSettings["client.svc"] will not be used.*/
        contentService.ClientRequestServiceSettings.MaxReceivedMessageSize = -1;

        // SPWcfServiceSettings has other Properties that you can set.
        SPWcfServiceSettings csomWcfSettings = new SPWcfServiceSettings();
        csomWcfSettings.MaxReceivedMessageSize = 146800640; // 140MB
        csomWcfSettings.MaxBufferSize = 146800640; // 140MB
        csomWcfSettings.TransferMode = System.ServiceModel.TransferMode.Streamed;
        contentService.WcfServiceSettings["client.svc"] = csomWcfSettings;

        contentService.Update();
    }

We have set transfermode to both Streamed and Buffered but with the same result.

Are there any other changes in form of config files that we have to update for this?

Thankful for any sugggestions / netify

3 Answers 3

1

Generally when I have to change the upload size, there is 2 things I check:

  • The global settings of the web application in the central administration, there is a param for the maximum upload size
  • The second is in the web.config:

<httpRuntime maxRequestLength="51200" />

Hope this would help.

But according to your error 401... I'm not sure this is due to the file size...

1
  • Thanks for you input. We have tried increasing the MaxRequestLength and maxAllowedContentLength in web.config but with no luck. We have also updated web.config in the ISAPI-folder where client.svc is deployed. We updated all bindings to allow 75 Mb which did not help either. As the response code is 401 it have to be something else. Strangely enough it only happens when the files are over 40 MB all other files in the same upload batch works fine.
    – netify
    May 2, 2012 at 10:22
1

I has this problem. I recommended SaveBinaryDirect method for you.

using (MemoryStream memoryStream=new MemoryStream(sourceFile.OpenBinary()))
                {
                    clientContext.ExecuteQuery();
                    Microsoft.SharePoint.Client.File.SaveBinaryDirect(clientContext,
                        targetUrl,memoryStream, true);
                    clientContext.ExecuteQuery();
                }
1

You may want to look at the <httpRuntime maxRequestLength="x" /> and <requestLimits maxAllowedContentLength="y"/> entries in web.config

2
  • Thanks for you input. We have tried increasing the MaxRequestLength and maxAllowedContentLength in web.config but with no luck. We have also updated web.config in the ISAPI-folder where client.svc is deployed. We updated all bindings to allow 75 Mb which did not help either. As the response code is 401 it have to be something else. Strangely enough it only happens when the files are over 40 MB all other files in the same upload batch works fine. –
    – netify
    May 2, 2012 at 10:24
  • the requestLimits value is within system.Webserver > security, so a 401 on overrun would fit. Did you ever find the problem? Dec 1, 2016 at 19:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.