public void ProcesFile(Microsoft.SharePoint.Client.File file, string filePath) { try { _clientContext.Load(file); _clientContext.ExecuteQuery(); var fileRef = file.ServerRelativeUrl; var fileInfo = Microsoft.SharePoint.Client.File.OpenBinaryDirect(_clientContext, fileRef); var fileName = string.Format("{0}\\{1}", filePath, (string)file.Name); var status = new FileDownloadStatus(FileType.File, file.Name, fileName); OnProgressUpdate(status); using (var fileStream = System.IO.File.Create(fileName)) { fileInfo.Stream.CopyTo(fileStream); } } catch (Exception exception) { OnErrorHandler(exception); return; } }
public FileDownloadStatus GetOrCreateFileDownloadStatus(int?FileDownloadStatusID) { if (FileDownloadStatusID.GetValueOrDefault(0) > 0) { return(this.FileDownloadStatus.FirstOrDefault(x => x.FileDownloadStatusID == FileDownloadStatusID)); } var newItem = new FileDownloadStatus(); this.FileDownloadStatus.AddObject(newItem); return(newItem); }
public FileDownloadStatus GetOrCreateFileDownloadStatus(int?FileDownloadStatusID) { FileDownloadStatus item = this.FileDownloadStatus.FirstOrDefault(x => x.FileDownloadStatusID == FileDownloadStatusID); if (item == null) { item = new FileDownloadStatus(); this.FileDownloadStatus.AddObject(item); } return(item); }
public async Task DownloadFiles(List <AddonFile> files, string source, DirectoryInfo modpackDirectory) { FileDownloadStatus[] downloaded = new FileDownloadStatus[files.Count]; for (int i = 0; i < downloaded.Length; i++) { downloaded[i] = new FileDownloadStatus(files[i].Size); } var downloadTask = DownloadWorker(files, source, modpackDirectory, downloaded); await PrintFilesDownload(downloadTask, downloaded); }
public void ProcessFolder(string outPutFolder, Folder folder) { try { _clientContext.Load(folder); _clientContext.ExecuteQuery(); if (folder.Name == "Forms") { return; } var srUrl = folder.ServerRelativeUrl; var filePath = outPutFolder; if (!outPutFolder.EndsWith("\\")) { filePath += "\\"; } filePath += srUrl.Replace('/', '\\') + "\\"; Directory.CreateDirectory(filePath); var files = folder.Files; var folders = folder.Folders; _clientContext.Load(files); _clientContext.Load(folders); _clientContext.ExecuteQuery(); var status = new FileDownloadStatus(FileType.Folder, folder.Name, folders.Count, files.Count); OnProgressUpdate(status); foreach (var file in folder.Files) { ProcesFile(file, filePath); } foreach (var contentFolder in folder.Folders) { ProcessFolder(outPutFolder, contentFolder); } } catch (Exception exception) { OnErrorHandler(exception); return; } }