Skip to content

Instantly share code, notes, and snippets.

@garima2510
Created June 30, 2014 05:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save garima2510/b1167e611ffb495848ec to your computer and use it in GitHub Desktop.
Save garima2510/b1167e611ffb495848ec to your computer and use it in GitHub Desktop.
O365 - CSOM upload large files
var spContext = SharePointContextProvider.Current.GetSharePointContext(HttpContext, SPHostUrl);
using (var clientContext = spContext.CreateUserClientContextForSPAppWeb())
{
if (clientContext != null)
{
//file is uploaded file. Could be read from Request.Files
using (FileStream fs = new FileStream(file.FileName, FileMode.Open))
{
//code for file size > 2MB. tested upto 50MB
FileCreationInformation newFile = new FileCreationInformation();
newFile.ContentStream = fs;
newFile.Url = Path.GetFileName(file.FileName);
newFile.Overwrite = true;
List docs = clientContext.Web.Lists.GetByTitle("List_Name");
Microsoft.SharePoint.Client.File uploadFile = docs.RootFolder.Files.Add(newFile);
clientContext.Load(uploadFile);
clientContext.ExecuteQuery();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment