DropBox Collection changed

Dec 7, 2011 at 3:20 PM

I have DropBox file download working! I did so by modifying the DropBoxTokenIssuer form included in the solution.  I added a textbox to specify the name of the file that I wanted to download and a Download button (see code below).  The event calls GetFiles, which is recursive. A couple of comments:

1.  The QuickStartGuide is out of date - I suspect that the project started as DropBox specific and evolved to being more generic.  That said, the developers have followed similar terminology as outlined in the QuickStartGuide.

2.  I encountered an error when I downloaded a file from within the foreach statement.  This occurs because DropBox keeps meticulous statistics of file usage - unfortunately, the statistics are embedded in the entry, which means that the collection changed.  I suspect that this also creates a problem if DropBox is used with multiple active users.

>> I made the following change in the SharpBox code which solves this problem.

a) Add IEnumerable<ICloudFileSystemEntry> Children() method to ICloudDirectoryEntry

b) Add implementation in BaseDirectoryEntry, which creates a copy of the current members.

c) foreach statement changed from 'foreach (ICloudFileSystemEntry entry in start)' to 'foreach (ICloudFileSystemEntry entry in start.Children())'.

private void buttonDownload_Click(object sender, EventArgs e)
{
    CloudStorage cs = new CloudStorage();
    cs.Open(_UsedConfig, _GeneratedToken);
    ICloudDirectoryEntry start = cs.GetRoot();
    StringBuilder sb = new StringBuilder();
    sb.Append("DropBox Contents" + Environment.NewLine);
    this.GetFiles(cs, sb, start);
    MessageBox.Show(sb.ToString());
    cs.Close();
}

string tempPCFolder = @"C:\temp";
private void GetFiles(CloudStorage cs, StringBuilder sb, ICloudDirectoryEntry start)
{
    foreach (ICloudFileSystemEntry entry in start.Children())
    {
        sb.Append(entry.Name + Environment.NewLine);
        if (entry is ICloudDirectoryEntry)
            this.GetFiles(cs, sb, entry as ICloudDirectoryEntry);
        else if (entry.Name == this.textBoxGetFile.Text)
        {
            ICloudFileSystemEntry file = cs.GetFileSystemObject(entry.Name, start);
            cs.DownloadFile(start, entry.Name, tempPCFolder);
            MessageBox.Show(@"File downloaded to " + tempPCFolder + entry.Name);
        }
    }
}

Coordinator
Dec 17, 2011 at 11:25 AM

Hi,

thanks for you contribution. Are you able to send me a patch file for your changes? I want to add them to the next release of SharpBox (will be 1.2 SR1)

 

Thanks

Dirk