方法一:

WebClient webClint = new WebClient();

webClint.DownloadFile(下载文件的路径,下载到本地的地址);

方法二:异步

WebClient webClint;
        float maxSpeed = 0;
        float currentSpeed = 0;
        float lastSpeed = 0;
        long lastReceive = 0;
        long reeciveSpan;
        TimeSpan span;
        DateTime start;
        DateTime lastTime;
        TimeSpan useTime;
        protected void Button1_Click(object sender, EventArgs e)
        {

webClint.DownloadProgressChanged += new DownloadProgressChangedEventHandler(webClint_DownloadProgressChanged);
  webClint.DownloadFileAsync(new Uri下载文件的路径, 下载到本地的地址);

}

void webClint_DownloadProgressChanged(object sender, DownloadProgressChangedEventArgs e)
        {
            span = DateTime.Now - lastTime;
            lastTime = DateTime.Now;
            useTime = lastTime - start;
            reeciveSpan = e.BytesReceived - lastReceive;
            currentSpeed = reeciveSpan * 1000 / (span.Milliseconds + 1) / 1024;
            maxSpeed = currentSpeed > maxSpeed ? currentSpeed : maxSpeed;
            lastSpeed = currentSpeed;
            lastReceive = e.BytesReceived;
           // progressBar1.Value = e.ProgressPercentage;
            this.Label1.Text = "已下载: " + e.BytesReceived / 1024 + "KB\n" +
                "总大小: " + e.TotalBytesToReceive / 1024 + "KB\n" +
                "百分比: " + e.ProgressPercentage + "%\n" +
                "当前速度: " + currentSpeed.ToString("F2") + "KB/s\n" +
                "大速度: " + maxSpeed.ToString("F2") + "KB/s\n" +
                "用时: " + (useTime.Minutes * 60 + useTime.Seconds) + "s";

if (e.BytesReceived == e.TotalBytesToReceive)
            {
                webClint.DownloadProgressChanged -= webClint_DownloadProgressChanged;
                webClint.Dispose();
                Response.Write("任务完成!");
                webClint.Dispose();
                //if (MessageBox.Show("是否关闭当前程序而立即安装?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation) == DialogResult.Yes)
                //{
                //    xiazai();
                //}
            }

}

winform 下载的更多相关文章

  1. winform下载网页源码

    public partial class Form1 : Form{public Form1(){InitializeComponent();} private void button1_Click( ...

  2. C# Winform下载文件并显示进度条

    private void btnDown_Click(object sender, EventArgs e) { DownloadFile("http://localhost:1928/We ...

  3. winform下载网页代码

    1:webClient client=new WebClient(); client.Downloadstring(地址) client.Downloadfile(地址,保存路径) 2:后台线程dow ...

  4. Winform 下载服务器安装包并安装

    代码中包含了检测本地安装盘符代码 一,定义下载委托事件(用于实现前台进度条更新和下载完成后事件的回调): private delegate void Action(); private string ...

  5. Winform下载文件并显示进度条

    本来是要研究怎样判断下载完成,结果找到这个方法,可以在这个方法完成之后提示下载完成. 代码如下: using System; using System.Collections.Generic; usi ...

  6. winform 下载文件显示进度和百分比

    /// <summary> /// 下载完成 /// </summary> private void DownloadFileCompleted() { IsComlate = ...

  7. 个人收藏--未整理—C# 上传下载文件

    Winform下载文件 /// <summary> /// 下载文件 /// </summary> /// <param name="URL"> ...

  8. ssential Diagram for Windows FormsC#/winForm类似visio的拓扑图节点连线控件免费下载

    Essential Diagram for Windows Forms是一款可扩展的.高性能的.NET平台下的拓扑图控件,可用于开发像Microsoft Visio一样的交互式地绘图和图解应用程序,在 ...

  9. SNF开发平台WinForm之六-上传下载组件使用-SNF快速开发平台3.3-Spring.Net.Framework

    6.1运行效果: 6.2开发实现: 1.先在要使用的项目进行引用,SNF.WinForm.Attachments.dll文件. 2.在工具箱内新建选项卡->选择项,浏览找到文件SNF.WinFo ...

随机推荐

  1. 简单的sql server->bs或cs数据交互模式

    主要记录工作当中遇到的一些问题和总结的一些经验 客户端请求-->web服务接口-->sql 语句执行(存储在数据库中)-->web服务(客户端通过调用web服务接口)-->返回 ...

  2. 剑指offer(58)对称的二叉树

    题目描述 请实现一个函数,用来判断一颗二叉树是不是对称的.注意,如果一个二叉树同此二叉树的镜像是同样的,定义其为对称的. 题目分析 主要是要懂得如何去判断对称,比如描述一颗树我们可以通过两个序列就能得 ...

  3. JS设计模式(6)命令模式

    什么是命令模式? 定义:将一个请求封装成一个对象,从而使您可以用不同的请求对客户进行参数化. 主要解决:在软件系统中,行为请求者与行为实现者通常是一种紧耦合的关系,但某些场合,比如需要对行为进行记录. ...

  4. Spring 学习——Spring AOP——AOP配置篇Aspect、Pointcut

    Schena——based AOP 声明 Spring所有的切面和通知器都必须放在一个<aop:config>标签内,可以同时配置多个<aop:config>元素. 每一个&l ...

  5. Bumped!【最短路】(神坑

    问题 B: Bumped! 时间限制: 1 Sec  内存限制: 128 MB 提交: 351  解决: 44 [提交] [状态] [命题人:admin] 题目描述 Peter returned fr ...

  6. 第八届蓝桥杯省赛 K倍区间

    问题描述 给定一个长度为N的数列,A1, A2, ... AN,如果其中一段连续的子序列Ai, Ai+1, ... Aj(i <= j)之和是K的倍数,我们就称这个区间[i, j]是K倍区间. ...

  7. _mount_allowed

    该表配置可以坐骑的使用区域,可能需要修改spell.dbc,允许在室内等特殊区域使用坐骑技能

  8. spring-cloud-config-server——Environment Repository

    参考资料: https://cloud.spring.io/spring-cloud-static/spring-cloud-config/1.4.0.RELEASE/single/spring-cl ...

  9. 理解SSL、HTTPS原理中的对称加密与非对称加密

    1.对称性加密 双方使用的同一个密钥,既可以加密又可以解密,这种加密方法称为对称加密,也称为单密钥加密. 简单来说就是:加密与解密都是同一个秘钥.   优点:通常在消息发送方需要加密大量数据时使用,算 ...

  10. [术语] CRUD 增删改查

    Data Manipulation Language, DML 数据操纵语言Insert update delete CRUD :create read update delete