Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

updating progress bar

Status
Not open for further replies.

gregaug

Programmer
Sep 9, 2005
61
US
hello,

I'm trying to get a progress bar to show upload status of a file, but I'm not sure how to actually activate the movement of the bar. I found some examples with .NET 2.0, but I'm using 1.1. Here's some of the code I have that deals with the upload:

FileInfo fInfo = new FileInfo(fname);
long numBytes = fInfo.Length;
FileStream fStream = new FileStream(fname, FileMode.Open, FileAccess.Read);
BinaryReader br = new BinaryReader(fStream);
byte [] data = br.ReadBytes((int)numBytes);
string url = http_Ref
WebClient myCli = new WebClient();
myCli.Headers.Add(filename);
myCli.Headers.Add(cook);//cook is my cookie


byte[] retdat;
retdat = myCli.UploadData(url,"POST", data);

I think the obvious part is that since I have the size of the file, if I can get the current status of the upload, I just need to change the progress bar to update that, but I don't know if/how to get the number of bytes sent in the upload.
 
A general principle is that you can make efficient use of a progress bar when you use any kind of loop to accomplish something. After every iteration of the loop, you update the value of the progress bar. It looks like your code makes no use of a loop, so there's nowhere to tell the progressbar to update itself with a new value.

Unless WebClient is a class you wrote and you have access to the code of the UploadData method. I expect that method to do the actual uploading byte for byte so you should control the progressbar from there.

Regards, Ruffnekk
---
Is it true that cannibals don't eat clowns because they taste funny?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top