Need to see if your shared folder is taking up space on your dropbox 👨💻? Find out how to check here.
Forum Discussion
RAJIB N.
10 years agoNew member | Level 1
How to get Progress Status while uploading/ downloading a file ( in .Net ) ?
I am using DropboxClient.Files.UploadAsync method for uploading file and
DropboxClient.Files.DownloadAsync for downloading.
Uploading and Downloading works perfectly but can't get the progress s...
RAJIB N.
10 years agoNew member | Level 1
Hello,
I have tried with downloading and uploading functions supplied by you, it gives the progress data alright, but I can not set that data to progress bar. I have worked with couple of hours but can not place that process status in the progress bar or any other way. I have attached codes of Upload
private async Task ChunkUpload()
{
string path = UploadFolder + "/" + UploadFile;
FileStream stream = UploadFileStream;
int chunkSize = 128 * 1024;
DropboxClient dbx = new DropboxClient(SystemVariables.WebAcccessToken);
int numChunks = (int)Math.Ceiling((double)stream.Length / chunkSize);
byte[] buffer = new byte[chunkSize];
string sessionId = null;
for (var idx = 0; idx < numChunks; idx++)
{
var byteRead = stream.Read(buffer, 0, chunkSize);
using (var memSream = new MemoryStream(buffer, 0, byteRead))
{
if (idx == 0)
{
var result = await dbx.Files.UploadSessionStartAsync(false, memSream);
sessionId = result.SessionId;
}
else
{
var cursor = new UploadSessionCursor(sessionId, (ulong)(chunkSize * idx));
var percentage = 100 * ((chunkSize * idx) / (double)stream.Length);
pValue = (int)Math.Ceiling((decimal)percentage);
// Approach 1
var progressIndicator = new Progress<int>(ReportProgress);
int uploads = await UploadProgress(progressIndicator);
// Approach 2
/*
Thread t = new Thread(new ThreadStart(this.DoProcess));
t.Start();
while (t.IsAlive) // while thread is running
{
Application.DoEvents(); // Allow UI to refresh if needed
Thread.Sleep(10000); // sleep a while to avoid processor load
t.Abort();
}*/
if (idx == numChunks - 1)
{
await dbx.Files.UploadSessionFinishAsync(cursor, new CommitInfo(path), memSream);
}
else
{
await dbx.Files.UploadSessionAppendV2Async(cursor,false, memSream);
}
}
}
}
}
public delegate void UpdateProgressBarDelegate(int progress);
public UpdateProgressBarDelegate UpdateProgressBar;
private void UpdateProgressBarMethod(int progress)
{
IAsyncResult result = this.progressBar1.BeginInvoke(
(MethodInvoker)delegate()
{
progressBar1.Value = progress;
Text = progress.ToString();
//txtLogDetails.Text = message;
});
}
private void DoProcess()
{
UpdateProgressBarMethod(pValue);
}
void ReportProgress(int value)
{
progressBar1.Value = value;
}
async Task<int> UploadProgress(IProgress<int> progress)
{
int processCount = await Task.Run<int>(() =>
{
if (progress != null)
{
progress.Report(pValue);
}
return pValue;
});
return processCount;
}
You can see the 2 approaches that I have tried to update progress bar value,
but can not see the update in progress bar.
It will be great if you provide the detail code for display updates in progress bar from the scratch.
About 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!