Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

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

share|improve this question

3 Answers 3

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();
                }
share|improve this answer

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...

share|improve this answer
    
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 '12 at 10:22

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

share|improve this answer
    
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 '12 at 10:24

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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