OK.Here's the part of the code.
try
{
wc = new WebClient();
wc.DownloadProgressChanged += new DownloadProgressChangedEventHandler(wc_DownloadProgressChanged);
wc.DownloadFileCompleted += new AsyncCompletedEventHandler(wc_DownloadFileCompleted);
lnkCancel.Enabled = true;
wc.DownloadFileAsync(new Uri(link), dwnFile);
lblResult.Visible = false;
}
catch (Exception)
{
MessageBox.Show(" Unexpected error occured.", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error);
try { File.Delete(dwnFile); if (_audio) File.Delete(filePath); }
catch (Exception) { }
unlockGui();
}
lblResult1.Text = "";
And here's the code for the DownloadFileCompleted
void wc_DownloadFileCompleted(object sender, AsyncCompletedEventArgs e)
{
lnkCancel.Enabled = false;
if (e.Cancelled)
{
MessageBox.Show("Download canceled.", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Information);
try
{
File.Delete(dwnFile);
if (_audio) File.Delete(filePath);
}
catch (Exception) { }
unlockGui();
return;
}
wc = null;
try
{
FileInfo f = new FileInfo(dwnFile);
if (f.Length < 4)
{
MessageBox.Show(" Error occured during download.", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error);
f = null;
try
{
if (_audio) File.Delete(filePath); File.Delete(dwnFile);
}
catch (Exception) { }
}
else
{
f = null;
progressBar1.Value = 0;
if (_audio)
{
toMp3(dwnFile);
try { File.Delete(dwnFile); }
catch (Exception) { }
}
this.Activate();
}
}
catch (Exception ex)
{
this.Activate();
MessageBox.Show("Error: " + ex.Message, Application.ProductName);
}
unlockGui();
lblResult.Text = "Done ";
}
Please help me. Hope this is enough.