0

所以我设置了一个小应用程序,我想用它从我的公共 Dropbox 文件夹中下载 A 文件夹,并将其中的所有内容下载到虚拟机。

如果我尝试:

var publicFolder = dropBoxStorage.GetFolder("/Public");
string targetFile = @"C:\Users\Michael\";
dropBoxStorage.DownloadFile(publicFolder,@"WS",targetFile);

WS 如果包含我要下载的所有内容的文件夹。

但是,当我运行代码时,我得到: 在此处输入图像描述

4

2 回答 2

1

SharpBox 不支持下载文件夹。我花时间写了一个函数,它应该递归地下载文件夹。(虽然没有测试过)。

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));
        }
    }
}
于 2013-10-04T14:37:45.990 回答
0

它也适用于以下代码..

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

        }
    }
于 2014-03-12T06:38:54.590 回答