0
votes

I am getting SharePoint Error: The server does not allow messages larger than 2097152 bytes error while uploading large file.

Can you please help me Below is my code:

        Folder currentRunFolder = site.GetFolderByServerRelativeUrl(barRootFolderRelativeUrl + "/" + newFolderName);
        FileCreationInformation newFile = new FileCreationInformation { Content = System.IO.File.ReadAllBytes(@p), Url = Path.GetFileName(@p), Overwrite = true };
        currentRunFolder.Files.Add(newFile);
        currentRunFolder.Update();

        context.ExecuteQuery();
1

1 Answers

1
votes

this is SP online or onPrem? if onPrem You may first try to extend a bit the settings

  • extend the max file upload on CA for this web application,
  • set on CA for this web application 'web page security Validation' on Never (in this link there is a screen how to set it)
  • extend timeout on IIS

also for large files you may consider using Microsoft.SharePoint.Client.File.SaveBinaryDirect method

please check one of my previous answers to a very similar method Upload file to sharepoint with httpclient here I give an example for SP 2013 (but would work in SP 2010 and 2016 as well) to upload a file under 2MB using Files.Add and larger files using SaveBinaryDirect