Download file and automatically save it to folder

后端 未结 6 652
夕颜
夕颜 2020-12-01 07:21

I\'m trying to make a UI for downloading files from my site. The site have zip-files and these need to be downloaded to the directory entered by the user. However, I can\'t

6条回答
  •  感情败类
    2020-12-01 07:28

    Why not just bypass the WebClient's file handling pieces altogether. Perhaps something similar to this:

        private void webBrowser1_Navigating(object sender, WebBrowserNavigatingEventArgs e)
        {
            e.Cancel = true;
            WebClient client = new WebClient();
    
            client.DownloadDataCompleted += new DownloadDataCompletedEventHandler(client_DownloadDataCompleted);
    
            client.DownloadDataAsync(e.Url);
        }
    
        void client_DownloadDataCompleted(object sender, DownloadDataCompletedEventArgs e)
        {
            string filepath = textBox1.Text;
            File.WriteAllBytes(filepath, e.Result);
            MessageBox.Show("File downloaded");
        }
    

提交回复
热议问题