Skip to content

Instantly share code, notes, and snippets.

@garima2510
Last active August 29, 2015 14:07
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save garima2510/416a807b43168c6bd5d1 to your computer and use it in GitHub Desktop.
O365 - Upload Large File Without File Stream
var spContext = SharePointContextProvider.Current.GetSharePointContext(HttpContext, SPHostUrl);
using (var clientContext = spContext.CreateUserClientContextForSPAppWeb())
{
if (clientContext != null)
{
FileCreationInformation newFile = new FileCreationInformation();
//here file is the selected file. In this case of type HttpPostedFileBase
newFile.ContentStream = file.InputStream;
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