static void Main(string[] args) { string targetSiteURL = @"https://xxx.sharepoint.com/sites/xxx"; string sourcePath = "C:\\Xie\\Test\\"; Console.WriteLine("Enter Your Username Please ------- "); string username = Console.ReadLine(); Console.WriteLine("Enter Your Password Please ------- "); SecureString password = GetPasswordOfYourSite(); SharePointOnlineCredentials onlineCredentials = new SharePointOnlineCredentials(username, password); using (ClientContext ctx = new ClientContext(targetSiteURL)) { ctx.Credentials = onlineCredentials; Web web = ctx.Web; ctx.Load(web); List targetList = ctx.Web.Lists.GetByTitle("TestFolder"); FolderCollection oFolderCollection = targetList.RootFolder.Folders; ctx.Load(oFolderCollection); ctx.ExecuteQuery(); foreach (Folder oFolder in oFolderCollection) { Console.WriteLine("Folder Name: " + oFolder.Name + " Folder URL: " + oFolder.ServerRelativeUrl); Folder folder = web.GetFolderByServerRelativeUrl(oFolder.ServerRelativeUrl); ctx.Load(folder); DirectoryInfo directory = new DirectoryInfo(sourcePath); FileInfo[] files = directory.GetFiles("*.*"); foreach (FileInfo file in files) { var filePath = sourcePath + file.Name; FileCreationInformation newFile = new FileCreationInformation(); newFile.Content = System.IO.File.ReadAllBytes(sourcePath + file.Name); newFile.Url = file.Name; newFile.Overwrite = true; Microsoft.SharePoint.Client.File newspFile = folder.Files.Add(newFile); } ctx.ExecuteQuery(); } Console.ReadLine(); } } private static SecureString GetPasswordOfYourSite() { ConsoleKeyInfo info; //Get the user's password as a SecureString SecureString securePassword = new SecureString(); do { info = Console.ReadKey(true); if (info.Key != ConsoleKey.Enter) { securePassword.AppendChar(info.KeyChar); } } while (info.Key != ConsoleKey.Enter); return securePassword; }