我想让进度条为下载变化的百分比运行时文件,进度与百分比在网页.aspx文件
我有代码,但运行时它会不会改变进度条的值
然后下载完成进度条直接进入100%。
请建议我为她的代码是我的示例代码。
private void DownloadFile(string url)
{
WebClient client = new WebClient();
client.UseDefaultCredentials = true;
client.DownloadProgressChanged += client_DownloadProgressChanged;
client.DownloadFileCompleted += new System.ComponentModel.AsyncCompletedEventHandler(client_DownloadFileCompleted);
// var url = _downloadUrls.Dequeue();
string FileName = url.Substring(url.LastIndexOf("/") + 1,
(url.Length - url.LastIndexOf("/") - 1));
client.DownloadFileAsync(new Uri(url), Server.MapPath(".") + "\\" + FileName);
//lblFileName.Text = url;
return;
}
void client_DownloadProgressChanged(object sender, DownloadProgressChangedEventArgs e)
{
double bytesIn = double.Parse(e.BytesReceived.ToString());
double totalBytes = double.Parse(e.TotalBytesToReceive.ToString());
double percentage = bytesIn/totalBytes * 100;
Label1.Text = "test";
//prg.Percentage = Convert.ToInt32(percentage);
prg.Percentage = int.Parse(Math.Truncate(percentage).ToString());
}
protected void Button1_Click(object sender, EventArgs e)
{
DownloadFile(Sample URL);
}