cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Announcements
Want to know what we learned at IBC? Check out our learnings on media, remote working and more right here.

Dropbox API Support & Feedback

Find help with the Dropbox API from other developers.

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

How to download a file which I want to use processbar for that?

How to download a file which I want to use processbar for that?

le h.
New member | Level 1

I want to use processbar, folderpicker for downloading.

This code just download. It not support for processbar, folderpicker.... and show a message if finished downloading.

public async void Download(string token, string path)
{
using (var dbx = new DropboxClient(token))
{
var download = await dbx.Files.DownloadAsync(path);
}
}

5 Replies 5

Greg-DB
Dropbox Staff

The Dropbox.NET SDK doesn't currently offer a way to get the progress of a download, but I'll be sure to pass this along as a feature request. 

It also doesn't offer a way to download folders in bulk, so you'll need to iterate through to download each desired file.

Greg-DB
Dropbox Staff

Actually, for reference, you can track progress if you use GetContentAsStreamAsync. E.g., you can do something like:

 var response = await client.Files.DownloadAsync(path);
ulong fileSize = response.Response.Size;
const int bufferSize = 1024 * 1024;

var buffer = new byte[bufferSize];

using (var stream = await response.GetContentAsStreamAsync())
{
    using (var file = new FileStream("Test", FileMode.OpenOrCreate))
    {
        var length = stream.Read(buffer, 0, bufferSize);

        while (length > 0)
        {
            file.Write(buffer, 0, length);
            var percentage = 100 * (ulong)file.Length / fileSize;
            // Update progress bar with the percentage.
            // progressBar.Value = (int)percentage
            Console.WriteLine(percentage);

            length = stream.Read(buffer, 0, bufferSize);
        }
    }
}

 

 

le h.
New member | Level 1

I have tried it but I don't know where is file be saved?

public async void Download(string token, string path)
{
using (var dbx = new DropboxClient(token))
{
var download = await dbx.Files.DownloadAsync(path);
}
}

 

Greg-DB
Dropbox Staff

In your sample code, the file isn't saved anywhere. The data is just available via the download object.

In my sample, the file is saved to the path "Test", but if you use that you should of course change that as desired.

Greg-DB
Dropbox Staff
The Dropbox API now offers the ability to download folders as zips:

https://www.dropbox.com/developers/documentation/http/documentation#files-download_zip

If you're using an official SDK, there will also be a corresponding method for this endpoint. In the .NET SDK, that's:

https://dropbox.github.io/dropbox-sdk-dotnet/html/M_Dropbox_Api_Files_Routes_FilesUserRoutes_Downloa...
Need more support?
Who's talking

Top contributors to this post

  • User avatar
    Greg-DB Dropbox Staff
  • User avatar
    le h. New member | Level 1
What do Dropbox user levels mean?