小编Jay*_*Jay的帖子

获取标签中的http文件大小,下载位置和URL

我正在使用它来下载文件并获取%信息和完成的信息.我想知道如何获取正在下载的文件的大小以及URL远程地址和保存文件的本地地址.

private void Form1_Load_1(object sender, EventArgs e)
        {
     label21.Text = "Download in progress...";
            WebClient webClient = new WebClient();
     webClient.DownloadFileCompleted += new AsyncCompletedEventHandler(Completed);
     webClient.DownloadProgressChanged += new DownloadProgressChangedEventHandler(ProgressChanged);
     webClient.DownloadFileAsync(new Uri("http://www.somesite.com/Update/Updates.zip.010"), @"Updates.zip.010");
 }

private void ProgressChanged(object sender, DownloadProgressChangedEventArgs e)
        {
            progressBar1.Value = e.ProgressPercentage; //Progress Bar Handler
            label1.Visible = true;
            label1.Text = progressBar1.Value.ToString() + " %"; //Adds percent to a label
        }

private void Completed(object sender, AsyncCompletedEventArgs e)
        {
            label11.Visible = true;
            label11.Text = "Done";
        }
Run Code Online (Sandbox Code Playgroud)

c# webclient download winforms progress-bar

1
推荐指数
1
解决办法
9462
查看次数

标签 统计

c# ×1

download ×1

progress-bar ×1

webclient ×1

winforms ×1