首页 > Web开发 > 详细

使用WebClient类对网页下载源码,对文件下载保存及异步下载并报告下载进度

时间:2016-05-29 23:08:09      阅读:339      评论:0      收藏:0      [点我收藏+]

技术分享

 

private void button1_Click(object sender, EventArgs e)
        {
            WebClient webclient = new WebClient();
            webclient.Proxy = null;
            webclient.Encoding = Encoding.UTF8;
            richTextBox1.AppendText(webclient.DownloadString(textBox1.Text.Trim()));
            webclient.Dispose();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            WebClient webclient = new WebClient();
            webclient.Proxy = null;
            webclient.DownloadFile(textBox2.Text, textBox3.Text);
            MessageBox.Show("成功!");
            webclient.Dispose();

        }

        private void button3_Click(object sender, EventArgs e)
        {
            WebClient webclient = new WebClient();
            webclient.Proxy = null;
            webclient.DownloadProgressChanged += webclient_DownloadProgressChanged;
            webclient.DownloadDataCompleted += webclient_DownloadDataCompleted;
            webclient.DownloadFileAsync(new Uri(textBox2.Text), textBox3.Text);
            webclient.Dispose();
        }

        void webclient_DownloadDataCompleted(object sender, DownloadDataCompletedEventArgs e)
        {
            MessageBox.Show("成功");
        }

        void webclient_DownloadProgressChanged(object sender, DownloadProgressChangedEventArgs e)
        {
            progressBar1.Value = e.ProgressPercentage;
        }

 

使用WebClient类对网页下载源码,对文件下载保存及异步下载并报告下载进度

原文:http://www.cnblogs.com/lunawzh/p/5540589.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!