Click to See Complete Forum and Search --> : download progress


Jef Patat
July 12th, 2006, 03:02 PM
Hi guru's,

at the moment I made this simple application with only one textbox and one button. When the button is pressed a file is downloaded and displayed in the textbox.
Everything runs fine but I would like to display messages indicating what operation is currently taking place ie , connecting , requesting, receiving..etc so that one can identify at which stage the connection is. How can I do this?

this is the simple code in button1_click:

try
{
WebClient client = new WebClient();
Stream data = client.OpenRead("http://ichart.finance.yahoo.com/table.csv?s=MFE&d=6&e=9&f=2006&g=d&a=9&b=7&c=2005&ignore=.csv"); StreamReader reader = new StreamReader(data);
string str = "";
str = reader.ReadLine();

while (str != null)
{
textBox1.AppendText(str + Environment.NewLine);
textBox1.SelectionStart = textBox1.Text.Length;
textBox1.ScrollToCaret();
str = reader.ReadLine();
}
data.Close();
}
catch (WebException exp)
{
MessageBox.Show(exp.Message, "Exception");
}

Thanks in advance

mcmcom
July 12th, 2006, 03:31 PM
this is a very tough one to solve. Since its not async your unable to do any updates using C# while a file upload is in progress. this means that you need javascript calls to display anything that may change "during" this time period. I have only ever managed to get a javascript static display up while downloading. A message that says "file upload in progress.. please wait."

However its quite hard to get something to talk to the upload component to determine bytes transferred.

One hack to accomidate this approach is to use chunk uploading. Basically you set a chunk size of say 16kb. and every 16kb of data you flush the upload pipe and at that time, if your clever you can add all the sent 16kb chunks and display their progress (but i dont know how to). The percentages for upload amount can be achieved by getting the fileSize (which you should know when they first select the file) and divide the uploaded amounts by that.

But its not easy...

hth,
mcm

PS if you figure it out please post me because i'd love to see it work!

Jef Patat
July 13th, 2006, 01:39 AM
I know it is not async, it's meant to be done in another way later on, however I'm only exploring this download stuff now.

Is there a better way to achieve this? I just want to process the data out of the csv file, but since download may take some time i would also like to display progress.

kind regards and...

thanks

mcmcom
July 13th, 2006, 09:15 AM
here are some links i have saved from trying to do what your trying:

//shows you how to do chunk uploading
http://www.codeproject.com/cs/webservices/DimeBufferedUpload.asp

//upload progress bar ISAPI module. This also has some good links in the article
http://www.codeproject.com/aspnet/File_Upload_Progress_Bar.asp

hth,
mcm