winform 下载

方法一:

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();
                //}
            }

}

时间: 2024-11-05 12:11:52

winform 下载的相关文章

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

代码中包含了检测本地安装盘符代码 1 一,定义下载委托事件(用于实现前台进度条更新和下载完成后事件的回调): 2 private delegate void Action(); 3 private string diverUrl = ConfigurationManager.AppSettings["diverUrl"];//http:形式 4 //页面初次加载事件 5 private void frmProgressBar_Load(object sender, EventArgs

C# WinForm源码

C# WinForm源码下载 Revit二次开发 - C#程序员的佳好选择 最近对winForm研究多一些,收录在分类里,不断更新.http://www.cnblogs.com/greatverve/category/267062.html http://revit.5d6d.com/ C#的WinForm源码真的是太少了.我找了些不错的,分享一下. 水晶报表入门示例(C# WinForm)http://revit.5d6d.com/thread-442-1-1.html C# 皮肤(WinFo

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

Winform下载文件 /// <summary> /// 下载文件 /// </summary> /// <param name="URL">下载文件地址</param> /// <param name="Filename">下载后的存放地址</param> /// <param name="Prog">用于显示的进度条</param> public

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

Essential Diagram for Windows Forms是一款可扩展的.高性能的.NET平台下的拓扑图控件,可用于开发像Microsoft Visio一样的交互式地绘图和图解应用程序,在节点存储图形对象,支持矢量和光栅图形. 具体功能: 支持多种导出格式:如位图.增强的元文件.SVG文件格式 控件采用清晰的MVC设计,把数据层.表现层和用户层分离 子节点属性可以从父节点继承,开发人员可以应用属性值到一个节点或所有子节点 支持在运行时添加自定义属性 多种线条节点和连接器,支持多种连接

WinForm皮肤 支持.NET4.0 IrisSkin4多彩皮肤演示和下载

IrisSkin4是一款.NET平台非常优秀的Winform皮肤,链接库文件仅544kb,使用方法也非常简单 IrisSkin4(IrisSkin4.dll + 73套皮肤)[下载地址] 使用方法: //仅在首个窗体中添加此代码即可实现所有窗体皮肤 new Sunisoft.IrisSkin.SkinEngine().SkinFile ="skins/MacOS.ssk"; 效果图如下: [Dome源码及IrisSkin4打包下载] WinForm皮肤 支持.NET4.0 IrisSk

vs2013中使用nuget下载cefsharp winform包

cefsharp是chrome的一个开源项目,基于webkit的一个浏览器.下载cefsharp需要安装nuget.之后管理nuget程序包,联机搜索cef即可找到winform包.

Winform中使用zxing实现二维码生成(附dll下载)

场景 zxing.dll下载 https://download.csdn.net/download/badao_liumang_qizhi/11623214 效果 实现 新建Winform程序,将上面下载的zxing.dll添加到引用. 拖拽一个按钮,双击进入其点击事件. private void button5_Click(object sender, EventArgs e) { //二维码要存储的内容 string codeString = "测试"; //生成二维码并返回Bit

winform自动更新并实现文件的批量异步下载

public partial class update : Form    {        private WebClient client;        int downfilenum = 0; //已下载文件数        int downlistnum = 0;//总下载文件数        List<string> list;        private string URl;        private string fileName;        private con

c#-Winform实时显示上传下载速率

代码如下: using System; using System.Drawing; using System.Collections; using System.ComponentModel; using System.Windows.Forms; using System.Data; using Echevil; namespace Network_Monitor_Sample { /// <summary> /// Summary description for Form1. /// &l