我想讓進度條爲下載變化的百分比運行時文件,進度與百分比在網頁.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);
}