Hello,
I want to know how to use the System.Net.WebClient in my application. Here is the part of the code:
System.Net.WebClient client = new System.Net.WebClient();
client.DownloadFile("http://updates.com/index.xml","c:\\update.xml");
That would download the file "index.xml" and save it in the local computer in drive C under a new name "update.xml". I would like my application to determine the file size of the file to be downloaded. I would like to make a progress bar showing the percent downloaded in the file in relation to its file size. Then after, when the download finishes, a MessageBox will appear stating that the download is completed.
Even if the progress bar is not included, that would suffice. What I would like to have is that when the file was downloaded in local machine of the user, a messagebox will appear stating that the downloading of updates is finish.
Hope you can help me in here.
Thanks and more power!
Ichi

How to Create a Download Update Form?
Eirian
Al Harlow
void wc_DownloadProgressChanged(object sender, DownloadProgressChangedEventArgs e)
{
long rec = e.BytesReceived; //received bytes so far
long percent = e.ProgressPercentage; //progress percentage
long total = e.TotalBytesToReceive; // total bytes
}
C# generated an error.
Error 1 The type or namespace name 'DownloadProgressChangedEventArgs' could not be found (are you missing a using directive or an assembly reference ) C:\Documents and Settings\Ichi Ban\Local Settings\Application Data\Temporary Projects\DownloadUpdate\Form1.cs 30 56 DownloadUpdate
What would be the possible cause Its quite unclear for me.
Thanks and more power!
Ichi
IMBack
I just don't understand but I just tried a couple of changes.
OLD:
wc.DownloadProgressChanged += new DownloadProgressChangedEventHandler(wc_DownloadProgressChanged);
NEW:
wc.DownloadProgressChanged += new System.Net.DownloadProgressChangedEventHandler(wc_DownloadProgressChanged);
Same goes to the function below.
void wc_DownloadProgressChanged(object sender, System.Net.DownloadProgressChangedEventArgs e)
{
...
}
Yet, I do not know the explanation. But I'm trying to check as to why is it. =D
Do you have any idea about this
Programm3r
SP534
oh, you can put a using System.Net on top of your code then you don't need this System.net stuff in your code anymore.
Amde
WXS123
I saw it in the control panel in the add, remove program.
There it is:
-Microsoft .NET Framework 1.1
-Microsoft .NET Framework 2.0
Is that a big problem
Ichi
Aazad
Use asychornized download and it gives you everything you need.
WebClient wc = new WebClient();
....
wc.DownloadFileCompleted+=
new AsyncCompletedEventHandler(wc_DownloadFileCompleted);wc.DownloadProgressChanged +=
new DownloadProgressChangedEventHandler(wc_DownloadProgressChanged);wc.DownloadFileAsync(new Uri("
http://updates.com/index.xml"), "c:\\index.html");....
void wc_DownloadProgressChanged(object sender, DownloadProgressChangedEventArgs e)
{
long rec = e.BytesReceived; //received bytes so far
long percent = e.ProgressPercentage; //progress percentage long total = e.TotalBytesToReceive; // total bytes}
...
void wc_DownloadFileCompleted(object sender, AsyncCompletedEventArgs e){
MessageBox.Show("Done");}