So I set up a little app that I would like to use to download A folder from my public Dropbox folder and all the content within that to a vm.
If I try:
var publicFolder = dropBoxStorage.GetFolder("/Public");
string targetFile = @"C:\Users\Michael\";
dropBoxStorage.DownloadFile(publicFolder,@"WS",targetFile);
WS if the Folder with all the content that I would like to download.
However when i run the code I get:
SharpBox does not support downloading folders. I took the time and wrote a function which should download the folder recursively. (haven't tested it though).
string remoteDirName = @"/Public/WS";
string targetDir = @"C:\Users\Michael\";
var remoteDir = dropBoxStorage.GetFolder(remoteDirName);
public static DownloadFolder(CloudStorage dropBoxStorage,ICloudDirectoryEntry remoteDir, string targetDir)
{
foreach (ICloudFileSystemEntry fsentry in remoteDir)
{
if (fsentry is ICloudDirectoryEntry)
{
DownloadFolder(dropBoxStorage, fsentry, Path.Combine(targetDir, fsentry.Name));
}
else
{
dropBoxStorage.DownloadFile(remoteDir,fsentry.Name,Path.Combine(targetDir, fsentry.Name));
}
}
}
It works fine with below code also..
var PublicFolder = dropBoxStorage.GetFolder("/Public");
if (PublicFolder != null && PublicFolder.ToList().Count > 0)
{
DownloadFolder(dropBoxStorage, PublicFolder as ICloudDirectoryEntry, targetPath);
}
public static void DownloadFolder(CloudStorage dropBoxStorage, ICloudDirectoryEntry remoteDir, string targetDir)
{
foreach (var fof in remoteDir.ToList())
{
if (fof is ICloudDirectoryEntry)
{
DirectoryInfo newDir = new DirectoryInfo(Path.Combine(targetDir, fof.Name));
if (!newDir.Exists)
{
Directory.CreateDirectory(Path.Combine(targetDir, fof.Name));
}
DownloadFolder(dropBoxStorage, fof as ICloudDirectoryEntry, Path.Combine(targetDir, fof.Name));
}
else
{
dropBoxStorage.DownloadFile(remoteDir, fof.Name, Path.Combine(targetDir));
}
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.