public static void Download()
{
using (WebClient wcDownload = new WebClient())
{
try
{
webRequest = (HttpWebRequest)WebRequest.Create(optionDownloadURL);
webRequest.Credentials = CredentialCache.DefaultCredentials;
webResponse = (HttpWebResponse)webRequest.GetResponse();
Int64 fileSize = webResponse.ContentLength;
strResponse = wcDownload.OpenRead(optionDownloadURL);
strLocal = new FileStream(optionDownloadPath, FileMode.Create, FileAccess.Write, FileShare.None);
int bytesSize = 0;
byte[] downBuffer = new byte[2048];
downloadForm.Refresh();
while ((bytesSize = strResponse.Read(downBuffer, 0, downBuffer.Length)) > 0)
{
strLocal.Write(downBuffer, 0, bytesSize);
PercentProgress = Convert.ToInt32((strLocal.Length * 100) / fileSize);
pBar.Value = PercentProgress;
pLabel.Text = "Downloaded " + strLocal.Length + " out of " + fileSize + " (" + PercentProgress + "%)";
downloadForm.Refresh();
}
}
catch { }
finally
{
webResponse.Close();
strResponse.Close();
strLocal.Close();
extractAndCleanup();
downloadForm.Hide();
}
}
}