SharePoint 2010: HowTo upload a file of the size of 1 GB using client object model

Article ID: 2529243 - View products that this article applies to.
Expand all | Collapse all


When you use SharePoint Client OM to upload files to SharePoint 2010 Document Library, uploading of files larger than 3 MB fail with the following error:

The remote server returned an error: (400) Bad Request.

Stack trace:

System.Net.WebException was unhandled
 Message=The remote server returned an error: (400) Bad Request.
      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 SPClientOMConsoleApp.Program.Main(String[] args) in C:\SPClientOMConsoleApp\SPClientOMConsoleApp\Program.cs:line 32
      at System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)
      at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
      at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
      at System.Threading.ThreadHelper.ThreadStart()

Sample program used to upload file using SharePoint 2010 Client OM:

            ClientContext clientContext = new ClientContext("http://server:10000/sites/testSite");
            Web web = clientContext.Web;
            List docLib = web.Lists.GetByTitle("doclib");
            byte[] bFile = System.IO.File.ReadAllBytes(@"C:\largeFile.docx");
            FileCreationInformation file = new FileCreationInformation();
            file.Content = bFile;
            file.Url = "http://server:10000/sites/testSite/doclib/" + "test.docx";
            Microsoft.SharePoint.Client.File newFile = docLib.RootFolder.Files.Add(file);


How to upload files with larger size, for example up to 1 GB or more, using Client Object Model in SharePoint 2010.


The default internal restrictions on file sizes and timeout settings halt uploading of larger files using Client Object Model in SharePoint.


More Information

At times you may see that the upload operation returns a timeout exception but this is critical only for very large file sizes which are close to 2 GB. Otherwise, it can be ignored using a try-catch block and you should see that the file got uploaded successfully.
Note This is a "FAST PUBLISH" article created directly from within the Microsoft support organization. The information contained herein is provided as-is in response to emerging issues. As a result of the speed in making it available, the materials may include typographical errors and may be revised at any time without notice. See Terms of Use for other considerations.


Article ID: 2529243 - Last Review: April 1, 2011 - Revision: 3.0
  • Microsoft SharePoint Foundation 2010

Give Feedback


Contact us for more help

Contact us for more help
Connect with Answer Desk for expert help.
Get more support from