Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C#
I added a progressbar and i wanted the program to launh the downloaded file but when the download is complete nothing happens at all!
 
public void button4_Click(object sender, EventArgs e)
        {
            using (System.IO.FileStream fs = System.IO.File.Create("\\aos075install.msi")) ;
 
            progressBar.Visible = true;
 
            WebClient webClient = new WebClient();
 

            webClient.DownloadFile("http://www.spadille.net/aos075install.msi", @"C:\aos075install.msi");
 
            webClient.DownloadProgressChanged += new DownloadProgressChangedEventHandler(ProgressChanged);
 

            webClient.DownloadFileCompleted += new AsyncCompletedEventHandler(Completed);
 

        }
             void ProgressChanged(object sender, DownloadProgressChangedEventArgs e)
                    {
                        progressBar.Value = e.ProgressPercentage;
                    }
 

 
              void Completed(object sender, AsyncCompletedEventArgs e)
                    {
                        MessageBox.Show("Download Successfull!");
                        progressBar.Visible = false;
                        System.Diagnostics.Process.Start("\\aos075install.msi");
                    }
 
              private void button5_Click(object sender, EventArgs e)
                    {
                        System.Diagnostics.Process.Start("\\Ace of Spades\\readme.txt");
                    }
 

thanks for help!
Posted 5-Feb-13 7:50am
Comments
Sergey Alexandrovich Kryukov at 5-Feb-13 14:14pm
   
What, you don't see 100% in ProgressChanges? How do you know that it's complete?
Did you run it under debugger to see if Completed is called, ever? Does it happen to all URLs you try, or this is only one case?
—SA
jibesh at 5-Feb-13 14:17pm
   
"when the download is complete nothing happens at all" is really nothing to us. you should tell what is the real problem you are facing. Please keep in mind that we cannot see your monitor,HDD or complete source code so you must provide enough details to solve your problem.
 
If you are expecting to start the MSI installed once the download is complete, check the path where you copied the file and running using Process start, they are different
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Change your ProgressChanged() method content to this:
 
     double bytesIn = double.Parse(e.BytesReceived.ToString());
     double totalBytes = double.Parse(e.TotalBytesToReceive.ToString());
     double percentage = bytesIn / totalBytes * 100;
     progressBar.Value = int.Parse(Math.Truncate(percentage).ToString());
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

I did not experience such problems, but I use different API which allows for more control and is more universal, System.Net.HttpWebRequest:
http://msdn.microsoft.com/en-us/library/system.net.httpwebrequest.aspx[^].
 
For a complete working sample, all in a single file, please see my past answer: how to download a file from internet[^].
 
My utility, HttpDownloader, allows to continue downloading of partially downloaded resource. This is possible, in particular, because HTTP response gives you the expected total size in the very beginning. This way, you can detect progress and indicate 100% progress when the size of the downloaded data becomes equal to the expected size.
 
Just the alternative you could consider, a very simple one but more universal.
 
—SA
  Permalink  
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 380
1 _Amy 255
2 Richard Deeming 250
3 Nirav Prabtani 223
4 CHill60 175
0 _Amy 110
1 Maciej Los 90
2 OriginalGriff 85
3 Mehdi Gholam 80
4 Sergey Alexandrovich Kryukov 75


Advertise | Privacy | Mobile
Web04 | 2.8.140721.1 | Last Updated 5 Feb 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100