2013-10-04 3 views
0

그래서 내 공용 Dropbox 폴더와 그 안에있는 모든 콘텐츠를 VM에 다운로드하는 데 사용하려는 작은 앱을 설정합니다.모든 콘텐츠가 재귀 적으로 다운로드되는 폴더, Sharpbox

내가하려고하면 :

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

WS을 다운로드하고자하는 모든 콘텐츠와 폴더 경우. 내가 코드를 실행하면

그러나 내가 얻을 : enter image description here

답변

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

이 너무 SharpBox의 어떤 버전을 관련이 있습니까? –

+0

또한 if 문에서 DownloadFolder 줄에 오류가 발생합니다. –

+1

내가 말했듯이, 그것은 테스트되지 않았습니다. 여전히 약간의 작업이 필요할 것입니다. 단지 일반적인 생각 일뿐입니다. 지정한 경우에는'DownloadFolder (dropBoxStorage, fsentry as ICloudDirectoryEntry, Path.Combine (targetDir, fsentry.Name)); '함수 대신에 최상위 패스가있을 수 있습니다. –

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

     } 
    } 
관련 문제