SP2010 Client Object Model 3 MB limit - updating maxReceivedMessageSize doesnt get applied
Asked Answered
S

3

5

I am using Client Object Model to interact with Sharepoint 2010. When I tried to upload documents greater than 3 MB using Client OM, it gave an error Bad Request. Microsoft suggests this to fix the problem. I tried that and updated the maxReceivedMessageSize property. It works fine after I restart the system, but doesnt get applied to a running sharepoint server.

I assume that as the setting might have been kept in memory, so needs an application reset, but I cudnt figure out what to reset. I have tried reseting different Sharepoint services. I have tried reseting Sharepoint website in IIS. Nothing helps.

Also, if I set a limit of 10 MB for example, I am able to upload documents around 7.5 MB. I think that is because of additional metadata (content-type properties etc). Is this correct behaviour or I need to change something else as well.

Would appreciate any help.

Regards.

Serafina answered 29/9, 2011 at 16:32 Comment(1)
I doubt there is a 25% of overhead of metadata for every payload. This would be unacceptable.Mccaslin
P
5

I have found this TechNet Forum entry which helped me solve this problem:

Tell SharePoint to increase its file size by following the steps below.
Ø As the SharePoint Site Administrator, access the SharePoint 2010 Management Shell by
1. On the Start menu, click All Programs.
2. Click Microsoft SharePoint 2010 Products.
3. Click SharePoint 2010 Management Shell.
Ø Then run the commands below.

get-PSSnapin - Registered
Add-PSSnapin Microsoft.SharePoint.Powershell
$ws = [Microsoft.SharePoint.Administration.SPWebService]::ContentService
$ws.ClientRequestServiceSettings.MaxReceivedMessageSize = 2147483647
$ws.Update()

Tell Asp.Net to increase its file size by following the steps below.
Ø Edit all web.config files involved to add the element '<httpRuntime>'.
When you are done, your addition should look like the example below.
Ø 2147483647 bytes is equal to 1.99 GB.
<system.web>
<httpRuntime useFullyQualifiedRedirectUrl="true" maxRequestLength="2147483647" requestLengthDiskThreshold="2147483647" executionTimeout="18000"/> </system.web>

Tell IIS 7.0 and up to increase its file size by following the steps below.
Edit all web.config files involved to add the element '<requestLimits>'.
When you are done, your addition should look like the example below.
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
<security>
<requestFiltering>
<requestLimits maxAllowedContentLength="2147483647" />
</requestFiltering>
</security>
</system.webServer>

I hope this helps!

Pushbike answered 16/7, 2012 at 10:8 Comment(0)
F
2

This is not an issue or hard limit of SharePoint. This is an operational upload limit that is set in place to protect the SharePoint infrastructure. While the operational upload limit is 2 MB, the binary upload limit is 50 MB.

There are currently 3 approaches:

  1. As you have already mentioned, increase the maxReceivedMessageSize.

  2. Use the SaveBinaryDirect methods

    These methods were introduced starting with SharePoint 2010. It basically uses Distributed Authoring Versioning (DAV) to make a PUT request. Using this approach, you have a 50 MB binary upload limit.

    Here is an example implementation of approach #2,

    string siteURL = "https://records.contoso.com";
    
    using (var context = new Microsoft.SharePoint.Client.ClientContext(siteURL))
    {
       context.Credentials = new NetworkCredential(
          "username", 
          "password", 
          "domain");
       string filePathToUpload = "C:\test\test.txt";
       context.ExecuteQuery();
    
       using (FileStream fs = new FileStream(filePathToUpload, FileMode.Open)
       {
          string targetURL = "/testsite/test.txt";
          Microsoft.SharePoint.Client.File.SaveBinaryDirect(
             context, 
             targetURL, 
             fs, 
             true);
       }
    }
    
  3. If you are using SharePoint 2013 or greater, you can use REST API. The upload limit is 2 GB.

Falcon answered 4/12, 2013 at 5:29 Comment(0)
M
0

as per the link you have sent the correct way to get what you need should be something like this:

public static void IncreaseMaxReceivedMessageSize ()
{
    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 = 10485760; // 10MB
    contentService.WcfServiceSettings["client.svc"] = csomWcfSettings;

    contentService.Update();
}

please show your code by editing your question and also explain which system you restart and then it works as opposed as restarting or recycling SP sites where you claim it does not work...

Mccaslin answered 30/9, 2011 at 8:59 Comment(1)
Thanks for your reply Davide. I just copied the same code from Microsoft link into my consol-application being run at server. By restarting the system, I meant, I restarted the machine and then it worked. I understand this is a WCF setting for Sharepoint Client OM, but I dont understand where is that located or how to reset that.Serafina

© 2022 - 2024 — McMap. All rights reserved.