How to OverCome limitations of uploading 2 MB File limit in SharePoint Using CSOM?
Hello SharePointers,
In SharePoint Online, 2013, 2016 environments , we can use CSOM to upload files into document library. While uploading Large files, there is a limitation of 2 MB . To overcome this, we can use the below CSOM script.
The below method will allows you to upload upto 10 MB.
public void UploadDocumentusingContentStream(ClientContext cc, string libraryName, string filePath)
{
Web web = cc.Web;
using (FileStream fs = new FileStream(filePath, FileMode.Open))
{
FileCreationInformation NewFile = new FileCreationInformation();
// using ContentStream property
fNewFile.ContentStream = fs;
NewFile.Url = System.IO.Path.GetFileName(filePath);
NewFile.Overwrite = true;
List docs = web.Lists.GetByTitle(“My Documents”);
Microsoft.SharePoint.Client.File uploadFile = docs.RootFolder.Files.Add(flciNewFile);
cc.Load(uploadFile);
cc.ExecuteQuery();
}
}
Happy SharePointing Folks!!