Hi all,
I've some requirement needs to upload files from local to Office365 Sharepoint Online Site Document Library using C# code?
public static void upload(){
Uri uri = new Uri("siteurl");
ClientContext context = new ClientContext(uri);
var passWord = new SecureString();
foreach (var c in "password") passWord.AppendChar(c);
context.Credentials = new SharePointOnlineCredentials("email", passWord);
Web web = context.Web;
FileCreationInformation newFile = new FileCreationInformation();
newFile.Content = System.IO.File.ReadAllBytes(@"C:\myfile.txt");
newFile.Url = "file uploaded via client OM.txt";
List docs = web.Lists.GetByTitle("Documents");
Microsoft.SharePoint.Client.File uploadFile = docs.RootFolder.Files.Add(newFile);
context.ExecuteQuery();
}
I don't know whether this method works and I'm always get issue for getting the ClientContext.
Thanks for your reply.