Search code examples
c#.netsharepointsharepoint-2019

SharePoint 2019 - The request message is too big


I have a small Console Application made with the help of .NET Framework 4.7.2. Its' purpose is to upload PDF files to a SharePoint 2019 site. There is a 2 MB file size limitation which I cannot find a way to avoid. The error message is as follows:

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

I've tried what was suggested in this article -> https://learn.microsoft.com/en-us/sharepoint/dev/solution-guidance/upload-large-files-sample-app-for-sharepoint

The ContentStream property of the FileCreationInformation in Microsoft.SharePoint.Client is missing in my code. I made sure that I am using the correct namespace and I also have the latest version of the dll. I later found out that the article is done on version 2013, so there is a big chance that the practises shows and outdated.

This is the way I am trying to upload a file:

 Folder folder = context.Web.GetFolderByServerRelativeUrl(path);
 FileCreationInformation FileToUpload = new FileCreationInformation();
                    
 FileToUpload.Content = System.IO.File.ReadAllBytes(file.FullName);
 FileToUpload.Url = AccountList.RootFolder.ServerRelativeUrl + filePath);
 FileToUpload.Overwrite = true;

 folder.Files.Add(FileToUpload);
 folder.Update();
 AccountList.Update();
 context.ExecuteQuery();

As I already said, I wanted to use ContentStream property instead of Content to avoid the 2 MB exception but it may be outdated because I can't get this property.

My question is, is there any way to bypass the 2 MB file upload limitation?


Solution

  • It turns out I had to install an additional Nuget package to see the ContentStream property of FileCreationInformation. My problem was immediately gone when I replaced Content property with ContentStream property.

    Nuget Package Name: Microsoft.SharePoint2019.CSOM
    Installation Command: Install-Package Microsoft.SharePoint2019.CSOM -Version 16.0.10337.12109