Sharepoint онлайн получай и загружай документы C# - PullRequest
0 голосов
/ 27 марта 2020

Как я могу получить доступ к библиотеке sharepoint и получить список файлов? Я хочу загрузить и загрузить файлы на sharepoint, используя C#. Мой логин на sharepoint запрашивает OTP при каждом входе в систему

1 Ответ

0 голосов
/ 30 марта 2020

Вы установили учетные данные для своего запроса?

Демо для загрузки.

using (ClientContext context = new ClientContext("https://xxx.sharepoint.com/sites/site"))
            {
                string s = "password";
                SecureString passWord = new SecureString();
                foreach (var c in s)
                    passWord.AppendChar(c);
                context.Credentials = new SharePointOnlineCredentials("user@xxx.onmicrosoft.com", passWord);

                //List docs = context.Web.Lists.GetByTitle("largeLib1");
                Folder folder = context.Web.GetFolderByServerRelativeUrl("/sites/site/largeLib1/set2");
                var filePath = @"C:\Lee\template.xlsx";
                using (FileStream fs = new FileStream(filePath, FileMode.Open))
                {                        
                    FileCreationInformation flciNewFile = new FileCreationInformation();

                    flciNewFile.ContentStream = fs;
                    flciNewFile.Url = System.IO.Path.GetFileName(filePath);
                    flciNewFile.Overwrite = true;                    
                    Microsoft.SharePoint.Client.File uploadFile = folder.Files.Add(flciNewFile);
                    context.Load(uploadFile);
                    context.ExecuteQuery();
                }                                                           
            }

загрузить демо

...