使用webclient下载,下载进度从回调函数中获取。
public void DownLoadFile(string url, string filename)
{
try
{
WebClient client = new WebClient();
Uri uri = new Uri(url);
client.DownloadProgressChanged += new DownloadProgressChangedEventHandler(DownloadProgressCallback);
client.DownloadFileCompleted += new AsyncCompletedEventHandler(DownloadFileCallback);
client.DownloadFileAsync(uri, filename);
}
catch (Exception e)
{
MessageBox.Show(e.Message);
}
}
private void DownloadProgressCallback(object sender, DownloadProgressChangedEventArgs e)
{