方法一:

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. P1605 迷宫

    P1605 迷宫 这是一道毒瘤题... 这是一道广搜题 bfs ... 代码: #include<cstdio> #include<iostream> #include< ...

  2. 怎样从外网访问内网Resin

    外网访问内网Resin 本地安装了Resin,只能在局域网内访问,怎样从外网也能访问本地Resin? 本文将介绍具体的实现步骤. 1. 准备工作 1.1 安装并启动Resin 默认安装的Resin端口 ...

  3. three.js 3d三维网页代码加密的实现方法

    http://www.jiamisoft.com/blog/17827-three-js-3dsanweiwangyejiami.html https://www.html5tricks.com/ta ...

  4. Python RabbitMQ RPC实现

    远程调用方法:R(remote)  P(procedure)  C(call) 为了说明如何使用RPC服务,我们将创建一个简单的客户端类. 它将公开一个名为call的方法,它发送一个RPC请求和块,直 ...

  5. elastichd安装部署

    1.下载 elastichd下载地址:https://github.com/360EntSecGroup-Skylar/ElasticHD/releases或是直接在linux下下载wget http ...

  6. Mac 配置教程-开发篇

    将 Mac 日常使用的软件和开发软件区分开,将之前写的 Mac 配置的文章分成了两篇: Mac 配置教程-日常篇 Mac 配置教程-开发篇 图床 iPic 设置快捷键 Command+Shift+u ...

  7. linux基础之正则表达式

    一.基本正则表达式 字符匹配 . : 匹配任意单个字符 [] : 匹配中括号中的任意单个字符 [^] : 匹配指定范围外的任意单个字符 空白字符:[:space:].数字:[:digit:].小写字母 ...

  8. 如何恢复IIS出厂默认设置

    How to restore IIS settings and Default Web Site? http://superuser.com/questions/704850/how-to-resto ...

  9. TCP/IP三次握手和四次挥手

    原博链接:https://www.cnblogs.com/Andya/p/7272462.html

  10. tar命令-压缩,解压缩文件

    tar: -c: 建立压缩档案 -x:解压 -t:查看内容 -r:向压缩归档文件末尾追加文件 -u:更新原压缩包中的文件 上面五个参数是独立的,压缩解压都要用到其中一个,可以和下面的命令连用但只能用其 ...