鐣岄潰
 
InBlock.gifSystem;
InBlock.gif using System.Collections.Generic;
InBlock.gif using System.ComponentModel;
InBlock.gif using System.Data;
InBlock.gif using System.Net.Sockets;
InBlock.gif using System.Net;
InBlock.gif using System.Threading;
InBlock.gif using System.Drawing;
InBlock.gif using System.Text;
InBlock.gif using System.Windows.Forms;
None.gif
None.gif namespace DownloadDemo
InBlock.gif{
InBlock.gif     public partial class Form1 : Form
InBlock.gif    {
InBlock.gif         public Form1()
InBlock.gif        {
InBlock.gif            InitializeComponent();
InBlock.gif        }
InBlock.gif         private WebClient client = new WebClient();
InBlock.gif        Thread th;
InBlock.gif         //自定义方法,提取文件名及路径
InBlock.gif         public void BeginDown()
InBlock.gif        {
InBlock.gif             string url = this.txtbUrl.Text.Trim().ToString();
InBlock.gif             int n = url.LastIndexOf( "/");
InBlock.gif             string address = url.Substring(0, n);
InBlock.gif             string fileName = url.Substring(n + 1, url.Length - n - 1);
InBlock.gif             string dir = this.txtbLocal.Text.Trim().ToString();
InBlock.gif             string localName = dir + "\\" + fileName;
InBlock.gif            WebRequest request = WebRequest.Create(url);
InBlock.gif             this.toolStripStatusLabel1.Text = "开始下载......";
InBlock.gif            client.DownloadFile(address, fileName);
InBlock.gif             this.toolStripStatusLabel1.Text = "下载完毕。";
InBlock.gif        }
InBlock.gif         //下载按钮事件
InBlock.gif         private void btDownload_Click( object sender, EventArgs e)
InBlock.gif        {
InBlock.gif            th = new Thread( new ThreadStart(BeginDown));
InBlock.gif            th.Start();
InBlock.gif        }
InBlock.gif    }
InBlock.gif}