i'm writing an application that downloading .xml files from our server, and retreive some data from them.
The file are data from parts we are using in my Department.
Some of files are 0Kb, meaning we don't have data from this part.
Now my problem is that the Webclient DownloadFileCompleted event is not firing when finishing downloading the 0Kb file.
Here's my code:
private void Get_Tool_Model()
{
if (System.Net.NetworkInformation.NetworkInterface.GetIsNetworkAvailable())
{
download_Tool_Model = true;
using (WebClient wc = new WebClient())
{
wc.UseDefaultCredentials = true;
wc.DownloadProgressChanged += (o, e) =>
{
double bytesIn = double.Parse(e.BytesReceived.ToString());
double totalBytes = double.Parse(e.TotalBytesToReceive.ToString());
double percentage = bytesIn / totalBytes * 100;
Dispatcher.Invoke(() => {
txt_progress.Text = "Downloaded " + e.BytesReceived + " of " + e.TotalBytesToReceive;
progress.Value = e.ProgressPercentage;
});
};
wc.DownloadFileCompleted += new AsyncCompletedEventHandler(Wc_DownloadFileCompleted);
wc.DownloadFileAsync(
// Param1 = Link of file
new System.Uri(path),
// Param2 = Path to save
"C:\\Tool_Model.xml"
);
}
}
}
private void Wc_DownloadFileCompleted(object sender, AsyncCompletedEventArgs e)
{
download_completed = true;
}
Thank you for your help.