Click here to Skip to main content
11,804,008 members (77,233 online)
Rate this: bad
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("", @"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;
              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
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?
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
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());
Rate this: bad
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:[^].

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.


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

  Print Answers RSS
0 OriginalGriff 430
1 CPallini 320
2 Sergey Alexandrovich Kryukov 234
3 CHill60 230
4 Suvendu Shekhar Giri 200
0 OriginalGriff 3,000
1 Maciej Los 1,910
2 KrunalRohit 1,862
3 CPallini 1,755
4 Richard MacCutchan 1,187

Advertise | Privacy | Mobile
Web02 | 2.8.151002.1 | Last Updated 5 Feb 2013
Copyright © CodeProject, 1999-2015
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