本文介绍了如何在使用Office 365的Sharepoint上确定ClientContext URL,Server相对的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 如何在使用Office 365的Sharepoint上确定ClientContext URL,Server相对。How to determine the ClientContext URL, Server relative while working on Sharepoint with Office 365.我的目标是下载存储在Documents-> User Created Folder->下的文件。文件的数量。My Goal is to download a file which is stored under Documents->User Created Folder-> LIst of files.我正在使用以下代码 ClientContext clientContext = new ClientContext("https://companyname.sharepoint.com"); SecureString passWord = new SecureString(); foreach (char c in "password".ToCharArray()) passWord.AppendChar(c); clientContext.Credentials = new SharePointOnlineCredentials("[email protected]", passWord); Web web = clientContext.Web; Microsoft.SharePoint.Client.File file = web.GetFileByGuestUrl(" "); clientContext.Load(file); ClientResult<Stream> stream = file.OpenBinaryStream(); clientContext.ExecuteQuery(); Kaleem。推荐答案 ClientContext网址是您的网站网址,例如: https:// yourtenant。 sharepoint.com/sites/TST 从文件夹下载文件的示例代码供您参考。class Program { private static void CopyStream(Stream src, Stream dest) { byte[] buf = new byte[8192]; for (; ; ) { int numRead = src.Read(buf, 0, buf.Length); if (numRead == 0) break; dest.Write(buf, 0, numRead); } } static void Main(string[] args) { string _SiteUrl = "https://domain.sharepoint.com/sites/tst"; using (var clientContext = new ClientContext(_SiteUrl)) { Console.ForegroundColor = ConsoleColor.Green; string password = "pw"; SecureString sec_pass = new SecureString(); Array.ForEach(password.ToArray(), sec_pass.AppendChar); sec_pass.MakeReadOnly(); clientContext.Credentials = new SharePointOnlineCredentials("[email protected]", sec_pass); Web web = clientContext.Web; Folder folder = web.GetFolderByServerRelativeUrl("/sites/TST/MyDoc4/Folder"); var files = folder.Files; clientContext.Load(files); clientContext.ExecuteQuery(); Regex regex = new Regex(_SiteUrl, RegexOptions.IgnoreCase); string localPath =@"C:\Lee\FileDownload"; foreach (var file in files) { clientContext.Load(file); Console.WriteLine(file.Name); ClientResult<Stream> stream = file.OpenBinaryStream(); clientContext.ExecuteQuery(); var fileOut = Path.Combine(localPath, file.Name); if (!System.IO.File.Exists(fileOut)) { using (Stream fileStream = new FileStream(fileOut, FileMode.Create)) { CopyStream(stream.Value, fileStream); } } } Console.WriteLine("done"); Console.ReadKey(); } } } 最好的问候, Lee 这篇关于如何在使用Office 365的Sharepoint上确定ClientContext URL,Server相对的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
09-13 01:39