CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Nov 2005
    Posts
    159

    download progress

    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:
    Code:
    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

  2. #2
    Join Date
    Jun 2003
    Location
    Toronto
    Posts
    805

    Re: download progress

    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!

  3. #3
    Join Date
    Nov 2005
    Posts
    159

    Re: download progress

    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
    Last edited by Jef Patat; July 13th, 2006 at 01:43 AM.

  4. #4
    Join Date
    Jun 2003
    Location
    Toronto
    Posts
    805

    Re: download progress

    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/webser...eredUpload.asp

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

    hth,
    mcm

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured