public void DownloadFolder(OAuth2Client client, DropNet.DropNetClient DownloadClient, string Dir, string DestinationDirectory, string API, bool IsConsole) { if (Directory.Exists(DestinationDirectory) == false) { if (IsConsole) { Console.WriteLine("Creating folder:" + DestinationDirectory); } Directory.CreateDirectory(DestinationDirectory); } var Data = client.GetFolderMeta(API, Dir); foreach (var item in Data.Contents) { if (item.IsDirectory) { DownloadFolder(client, DownloadClient, item.Path, DestinationDirectory + @"\" + item.Path.Split('/')[item.Path.Split('/').Count() - 1], API, IsConsole); } else { if (IsConsole) { Console.WriteLine("Downloading:" + Path.GetFileName(item.Path)); } var NewFile = DownloadClient.GetFile(item.Path); using (var fileStream = new FileStream( DestinationDirectory + @"\" + Path.GetFileName(item.Path), FileMode.CreateNew, FileAccess.ReadWrite)) { fileStream.Write(NewFile, 0, NewFile.Length); fileStream.Flush(true); } } } }
/// <summary> /// Extract error message from given exception /// </summary> /// <param name="error">Error object</param> /// <returns>Error message</returns> string ExtractErrorMessage(DropNet.Exceptions.DropboxException error) { string errormessage = error.Message ?? ""; var resp = error.Response; if (resp.ContentType == "application/json") { try { var errormodel = JsonConvert.DeserializeObject<DropBoxErrorJsonModel>(resp.Content); if (errormodel != null) errormessage = errormodel.error; } catch (System.Exception e) { } } return errormessage; }
private static bool FolderExists(DropNet.Models.MetaData backupFolder) { return backupFolder != null && !backupFolder.Is_Deleted && backupFolder.Is_Dir; }