The Soldier of Fortune

Musing on Microsoft Digital Transformation

Limitation of uploading big file to SharePoint 2013 with CSOM

We have recently rolled out an Outlook plugin that integrates with SharePoint. The plugin allows end users to upload selectable email to SharePoint 2013 libraries. Client-side object model (CSOM) is used for the plugin development. We realized that if the email’s size was more than 2MB, it was unable to be uploaded to SharePoint 2013 libraries. The following message was thrown out:

“The request message is too big. The server does not allow messages larger than 2097152 bytes.”

We just figured out that SharePoint 2013 has limit when using CSOM. The default value to make a request through CSOM is 2MB if you have never paid attention to CSOM setting. There is a property called MaxReceivedMessageSize in SPWebService object that is adjustable.

To allow big files to be uploaded through CSOM, use the following PowerShell snippet code:

$a = [Microsoft.SharePoint.Administration.SPWebService]::ContentService
$a.ClientRequestServiceSettings.MaxReceivedMessageSize = 209715200

Note: make sure SharePoint Timer service is stopped before you execute the above PowerShell

You could programmatically set the MaxReceivedMessageSize property using C# snippet code below

public static void IncreaseMaxReceivedMessageSize()
SPWebService contentService = SPWebService.ContentService;
contentService.ClientRequestServiceSettings.MaxReceivedMessageSize = 10485760;  // 10MB

If you use built-in SharePoint API, you might need to read this article: Quick tip to overcome limitation of uploading using SharePoint web service

For more information about increasing the Maximum Message Size, read this article

[Update – 27/01/2015] Jason has a good tip for uploading large files via CSOM with SaveBinaryDirect method and MemoryStream.

« »

© 2017 The Soldier of Fortune. Theme by Anders Norén.