• 大小: 446KB
    文件类型: .rar
    金币: 2
    下载: 1 次
    发布日期: 2021-06-13
  • 语言: C#
  • 标签: C#  Winform  Http下载  

资源简介

利用c# 简单实现基于http的文件下载,带进度条。暂不支持断点续传。

资源截图

代码片段和文件信息

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Net;
using System.IO;
using System.Threading;

namespace DownLoadHttp
{
    public partial class Form1 : Form
    {
        
        public Form1()
        {
            //防止线程间操作无效
            //如果不写,会产生: 
            //线程间操作无效: 从不是创建控件“btnDown”的线程访问它。
            //因为控件的创建在另外一个线程。
            Control.CheckForIllegalCrossThreadCalls = false;
            InitializeComponent();
            this.txtSrcAddress.Text = @“http://www.100-try.com/soft/Viewdll.rar“;
            this.txtTarAddress.Text = @“D:“;
        }

        private void btnDown_Click(object sender EventArgs e)
        {
            Thread th = new Thread(new ThreadStart(this.StartDownLoad));
            th.Start();
        }

        private void StartDownLoad()
        {

            this.btnDown.Enabled = false;
            this.statusBar.Text = “正在下载...“;
            //要下载的文件http地址
            //例如:(http://www.YourSiteAddress.com/SoftWare/Soft1.rar)
          string url = this.txtSrcAddress.Text;

            //截取文件名称
            int n = url.LastIndexOf(‘/‘);
            string fileName = url.Substring(n + 1 url.Length - n - 1);

            //保存的路径+\文件名
          string dir = this.txtTarAddress.Text;
          string filepath = dir+“\\“+fileName;

           HttpDownLoad httpDownLoad = new HttpDownLoad();

            httpDownLoad.httpDownFile(urlfilepath this.toolStripProgressBar this.toolStripStatusLabel);
           

            this.btnDown.Enabled = true;
        }
    }
}

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

     文件      12288  2009-10-09 16:09  DownLoadHttp\bin\Debug\DownLoadHttp.exe

     文件      30208  2009-10-09 16:09  DownLoadHttp\bin\Debug\DownLoadHttp.pdb

     文件      14328  2009-10-09 16:13  DownLoadHttp\bin\Debug\DownLoadHttp.vshost.exe

     文件        490  2007-07-21 01:33  DownLoadHttp\bin\Debug\DownLoadHttp.vshost.exe.manifest

     文件        828  2009-10-09 11:19  DownLoadHttp\bin\Debug\test.txt

     文件     493568  2009-10-09 14:28  DownLoadHttp\bin\Debug\Viewdll.exe

     文件     202351  2009-10-09 15:04  DownLoadHttp\bin\Debug\viewdll.rar

     文件      29696  2009-10-09 14:31  DownLoadHttp\bin\Debug\单项制作规范.doc

     文件       3399  2009-10-09 16:13  DownLoadHttp\DownLoadHttp.csproj

     文件        913  2009-10-09 16:13  DownLoadHttp\DownLoadHttp.sln

    ..A..H.     10240  2009-10-09 16:13  DownLoadHttp\DownLoadHttp.suo

     文件       1894  2009-10-09 16:09  DownLoadHttp\Form1.cs

     文件       6065  2009-10-09 16:09  DownLoadHttp\Form1.Designer.cs

     文件       6011  2009-10-09 16:09  DownLoadHttp\Form1.resx

     文件       5604  2009-10-09 16:08  DownLoadHttp\HttpDownLoad.cs

     文件        647  2009-10-09 16:13  DownLoadHttp\obj\Debug\DownLoadHttp.csproj.FileListAbsolute.txt

     文件        847  2009-10-09 16:09  DownLoadHttp\obj\Debug\DownLoadHttp.csproj.GenerateResource.Cache

     文件      12288  2009-10-09 16:09  DownLoadHttp\obj\Debug\DownLoadHttp.exe

     文件        180  2009-10-09 16:09  DownLoadHttp\obj\Debug\DownLoadHttp.Form1.resources

     文件      30208  2009-10-09 16:09  DownLoadHttp\obj\Debug\DownLoadHttp.pdb

     文件        180  2009-10-09 15:41  DownLoadHttp\obj\Debug\DownLoadHttp.Properties.Resources.resources

     文件        473  2009-10-09 09:45  DownLoadHttp\Program.cs

     文件       1368  2009-10-09 09:45  DownLoadHttp\Properties\AssemblyInfo.cs

     文件       2874  2009-10-09 09:45  DownLoadHttp\Properties\Resources.Designer.cs

     文件       5612  2009-10-09 09:45  DownLoadHttp\Properties\Resources.resx

     文件       1097  2009-10-09 09:45  DownLoadHttp\Properties\Settings.Designer.cs

     文件        249  2009-10-09 09:45  DownLoadHttp\Properties\Settings.settings

     目录          0  2009-10-09 16:12  DownLoadHttp\obj\Debug\Refactor

     目录          0  2009-10-09 16:12  DownLoadHttp\obj\Debug\TempPE

     目录          0  2009-10-09 16:12  DownLoadHttp\bin\Debug

............此处省略8个文件信息

评论

共有 条评论