I am learning how to use http requests and webclient in C# windows forms. Currently I have gotten the following code from Example and I am trying to make it work as well as understand it.
The code executes successfully and displays the messagebox "Download Complete" box but it does not actually download the file. Would someone explain to me how this works and what I am doing wrong?
private void btnDownload_Click(object sender, EventArgs e)
{
string filepath = txtBxSaveTo.Text.ToString();
WebClient webClient = new WebClient();
webClient.DownloadFileCompleted += new AsyncCompletedEventHandler(Completed);
webClient.DownloadProgressChanged += new DownloadProgressChangedEventHandler(ProgressChanged);
webClient.DownloadFileAsync(new Uri("http://download.thinkbroadband.com/10MB.zip"), filepath);
}
private void ProgressChanged(object sender, DownloadProgressChangedEventArgs e)
{
progressBar.Value = e.ProgressPercentage;
}
private void Completed(object sender, AsyncCompletedEventArgs e)
{
MessageBox.Show("Download completed!");
}
private void btnSavetoLocation_Click(object sender, EventArgs e)
{
FolderBrowserDialog selectedFolder = new FolderBrowserDialog();
if (selectedFolder.ShowDialog() == DialogResult.OK)
{
txtBxSaveTo.Text = selectedFolder.SelectedPath;
}
}
}
}