Need to see if your shared folder is taking up space on your dropbox 👨‍💻? Find out how to check here.

Forum Discussion

Manjit S.'s avatar
Manjit S.
New member | Level 1
11 years ago

Downloading progress in when download with dropbox client in .net?

I am using dropbox api to download the files and i am using drop box client to download file now i want to show the progress bar to the .How it is possible? I am using following code to download file.

DropboxClient dbx = new DropboxClient(user.DropboxAccessToken,10,null,httpClient);


using (var response = await dbx.Files.DownloadAsync(@"" + "/" + file))
{
var ufile =await response.GetContentAsStreamAsync();
}

4 Replies

Replies have been turned off for this discussion
  • Greg-DB's avatar
    Greg-DB
    Icon for Dropbox Community Moderator rankDropbox Community Moderator
    11 years ago

    No, unfortunately I don't believe the .NET SDK offers a way to track progress of the download. I'll send this along as a feature request though.

  • Brandon T.6's avatar
    Brandon T.6
    New member | Level 1
    11 years ago

    I'm assuming the code above works for you? I am trying to use similar code and the file isn't downloading for some reason. I don't get an error message, I just get a blank screen. I have the using(var response = await.dbx.Files.DownloadAsync("/" + file)
    {

    }

    What code actually downloads it and where does it download it? Does the response.GetContentAsStreamAsync() function download the file?

  • Greg-DB's avatar
    Greg-DB
    Icon for Dropbox Community Moderator rankDropbox Community Moderator
    11 years ago

    Hi Brandon, it sounds like your question is more about downloading files in general when using the .NET SDK, as opposed to getting progress of a download. Can you open a new thread with the details of any issue(s) you're having so we can help you specifically without spamming Manjit? Thanks in advance! 

  • Greg-DB's avatar
    Greg-DB
    Icon for Dropbox Community Moderator rankDropbox Community Moderator
    10 years ago

    You can now track progress using 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);
            }
        }
    }

     

     

About Dropbox API Support & Feedback

Node avatar for Dropbox API Support & Feedback
Find help with the Dropbox API from other developers.

The Dropbox Community team is active from Monday to Friday. We try to respond to you as soon as we can, usually within 2 hours.

If you need more help you can view your support options (expected response time for an email or ticket is 24 hours), or contact us on X, Facebook or Instagram.

For more info on available support options for your Dropbox plan, see this article.

If you found the answer to your question in this Community thread, please 'like' the post to say thanks and to let us know it was useful!