Search code examples
c#dropbox-apisharpbox

Download folder with all content recursively, Sharpbox


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: enter image description here


Solution

  • 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));
            }
        }
    }