码迷,mamicode.com
首页 > Web开发 > 详细

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

时间:2016-05-29 23:11:19      阅读:336      评论: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
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!