473,385 Members | 1,400 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Tracking upload progress

HaLo2FrEeEk
404 256MB
I've written a program that uploads a file via FTP to my server. It allows you to select the file you want to upload, type the path to upload it to, then upload it. While it's uploading it uses a loop to keep track of the progress in this format:

bytes uploaded / total bytes

I'm trying to also have it display the percent done (something I thought would be super simple) by having a double called percentDone. Inside the while loop I do this:

percentDone = (int)(totalUploaded / finfo.Length) * 100;

And then the line that prints is:

textbox1.Text = "Uploaded " + totalUploaded + "/" + finfo.Length + " bytes - (" + percentDone + "%)";

Problem is while I'm uploading the percent stays at 0 until the upload is complete, then it jumps to 100%. I've got Application.DoEvents(); inside my while loop, so the textbox text DOES update the uploaded / total part, just not the percent.

Am I doing something wrong? I've tried taking a screenshot of the program while it was uploading and dividing the bytes uploaded by the total bytes, I used these numbers:

657408 / 6598144

Which should give me 0.09963...multiplied by 100 gives me 9.96%. I just want to floor the result, so I'd think that Math.Floor(percentDone) would work. Problem is, like I said, percentDone just stays at 0 for the whole time until the upload is complete.

Please help me out with this, what the heck am I doing wrong?
Jan 7 '10 #1
2 3289
cloud255
427 Expert 256MB
Hi,

Could you post your full code please.
Check the background worker class which contains DoWork and ProgressChanged members. The DoWork class will allow you to perform the download in the background on a separate thread while the ProgressChanged will allow you to update the download progress in real time.
Jan 7 '10 #2
HaLo2FrEeEk
404 256MB
I've been advised before to NOT use the DoWork class. I can't really post the full code because it's really long, and it's an upload, not a download.

Regardless, I figured it out. Apparently dividing an int by another int will only return an int, meaning I was only getting 0 and 1 (multipled by 100 was 0 and 100.) All I had to do was make one of the numbers a double, that was easy, I just cast the totalDownloaded as a double and it worked. All I had to do was round the number to 2 decimal points and I'm golden.
Jan 7 '10 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

9
by: Bob Bedford | last post by:
I've a page where the user may enter some values and upload some pictures. Unfortunately, some pictures coming from digital camera are very big, and take a lot of time for uploading. I've...
4
by: Uncle Ben | last post by:
Is there any good and reliable Upload Component for ASP (or ASP.NET)? I need one which provides an upload status bar. As well, it must be able to handle more than 4 gigabytes of data transfer....
3
by: Brian Birtle | last post by:
**** A CHALLENGE TO THE GURUS - refute the statement "It's impossible to build a file upload progress meter using ASP.NET" **** First person to prove me wrong gets "All Time .NET Programming GOD"...
4
by: Pavils Jurjans | last post by:
Hello, I have the following setup: The page that contains the form with file upolad HTML control resides on another server that doesn't have ASP.NET available. It may well be just static...
6
by: Marko Vuksanovic | last post by:
I am trying to implement a file upload progress indicator (doesn't have to be a progress bar) using atlas... I do realize that the indicator cannot be implemented using Update panel control, but is...
1
by: Marko Vuksanovic | last post by:
I used the following code for implementing a file upload progress indicator, using UpdateProgress Panel, though I have a problem that FileUpload.Has File always returns false. Any suggestions what...
5
by: LtCommander | last post by:
Hello all, 1. I am a little new to ASP.NET, so please bear with me. 2. I am trying to create a very simple website which requires an upload box (end user file sizes may be anywhere between 1MB...
3
by: markus.rietzler | last post by:
i want to do (multiple) file upload(s) and display a progress bar. with firefox and safari it is no problem at all. only IE makes some problems. my script is based on ajax-uploader, which can be...
3
by: shapper | last post by:
Hello, I need to upload a file. Can I only do this with the File Upload control? I also need the following: - Send upload info, upload percentage, continuously to a JavaScript function so...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.