Skip to content

Instantly share code, notes, and snippets.

@garima2510

garima2510/uploadfile.cs

Last active Aug 29, 2015
Embed
What would you like to do?
O365 - CSOM upload 2MB files
var spContext = SharePointContextProvider.Current.GetSharePointContext(HttpContext, SPHostUrl);
using (var clientContext = spContext.CreateUserClientContextForSPAppWeb())
{
if (clientContext != null)
{
//code for file size < 2MB
//file is the input which we uploaded. It can be taken from Request.Files
FileCreationInformation newFile = new FileCreationInformation();
newFile.Content = System.IO.File.ReadAllBytes(file.FileName);
newFile.Url = Path.GetFileName(file.FileName);
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
You can’t perform that action at this time.