Dropbox API Downloading a file Downloading a file using the Dropbox .NET library with progress tracking

Help us to keep this website almost Ad Free! It takes only 10 seconds of your time:
> Step 1: Go view our video on YouTube: EF Core Bulk Extensions
> Step 2: And Like the video. BONUS: You can also share it!

Example

This uses the Dropbox .NET SDK to download a file from the Dropbox API at the remote path to the local file "Test", while tracking progress:

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


Got any Dropbox API Question?