This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
string filePath = "/TestLibrary/TestDocument.pptx"; | |
var spContext = SharePointContextProvider.Current.GetSharePointContext(HttpContext); | |
using (var sourceContext = spContext.CreateUserClientContextForSPHost()) | |
{ | |
Microsoft.SharePoint.Client.File sourceFile = sourceContext.Web.GetFileByServerRelativeUrl(filePath); | |
//file stream will be used to upload in destination library | |
var fileStream = sourceFile.OpenBinaryStream(); | |
sourceContext.Load(sourceFile, k => k.ServerRelativeUrl, k => k.Name); | |
sourceContext.ExecuteQuery(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using Microsoft.SharePoint.Client; | |
using Microsoft.SharePoint.Client.UserProfiles; | |
using (ClientContext clientContext = new ClientContext("https://tenant.sharepoint.com/")) | |
{ | |
SecureString passWord = new SecureString(); | |
foreach (char c in "your_password".ToCharArray()) passWord.AppendChar(c); | |
clientContext.Credentials = new SharePointOnlineCredentials("your_email_id", passWord); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using Microsoft.SharePoint.Client; | |
using Microsoft.SharePoint.Client.UserProfiles; | |
using (ClientContext clientContext = new ClientContext("https://tenant.sharepoint.com/")) | |
{ | |
SecureString passWord = new SecureString(); | |
foreach (char c in "your_password".ToCharArray()) passWord.AppendChar(c); | |
clientContext.Credentials = new SharePointOnlineCredentials("your_email_id", passWord); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
NewerOlder