Downloaded file using webclient.DownloadFileAsync has 0KB

前端 未结 4 1952
情话喂你
情话喂你 2020-12-11 14:43

I\'m trying to download zend-framework (from http://framework.zend.com/releases/ZendFramework-1.11.11/ZendFramework-1.11.11.zip) simply using WebClient

strin         


        
4条回答
  •  囚心锁ツ
    2020-12-11 15:07

    Try to handle the DownloadProgressChanged and DownloadFileCompleted event.

    private void button1_Click(object sender, EventArgs e)
      {
       string url = "http://framework.zend.com/releases/ZendFramework-1.11.11/ZendFramework-1.11.11.zip";
       WebClient downloader = new WebClient();
       downloader.DownloadFileCompleted += new AsyncCompletedEventHandler(downloader_DownloadFileCompleted);
       downloader.DownloadProgressChanged += new DownloadProgressChangedEventHandler(downloader_DownloadProgressChanged);
       downloader.DownloadFileAsync(new Uri(url), "C:\\temp.zip");
      }
    
     void downloader_DownloadProgressChanged(object sender, DownloadProgressChangedEventArgs e)
       {
          label1.Text = e.BytesReceived + " " + e.ProgressPercentage;
        }
      void downloader_DownloadFileCompleted(object sender, AsyncCompletedEventArgs e)
       {
           if (e.Error != null)
             MessageBox.Show(e.Error.Message);
           else
             MessageBox.Show("Completed!!!");
       }
    

提交回复
热议问题