
System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Net.Sockets;
using System.Net;
using System.Threading;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace DownloadDemo

{
public partial
class Form1 : Form

{
public Form1()

{

InitializeComponent();

}
private WebClient client =
new WebClient();

Thread th;
//自定義方法,提取文件名及路徑
public
void BeginDown()

{
string url =
this.txtbUrl.Text.Trim().ToString();
int n = url.LastIndexOf(
"/");
string address = url.Substring(0, n);
string fileName = url.Substring(n + 1, url.Length - n - 1);
string dir =
this.txtbLocal.Text.Trim().ToString();
string localName = dir + "\\" + fileName;

WebRequest request = WebRequest.Create(url);
this.toolStripStatusLabel1.Text =
"開始下載......";

client.DownloadFile(address, fileName);
this.toolStripStatusLabel1.Text =
"下載完畢。";

}
//下載按鈕事件
private
void btDownload_Click(
object sender, EventArgs e)

{

th =
new Thread(
new ThreadStart(BeginDown));

th.Start();

}

}

}