WebClient client = new WebClient();
第一种
string URLAddress = @"http://files.cnblogs.com/x4646/tree.zip";
string receivePath=@"C:\";
client.DownloadFile(URLAddress, receivePath + System.IO.Path.GetFileName(URLAddress));
就OK了。
第二种
Stream str = client.OpenRead(URLAddress);
StreamReader reader = new StreamReader(str);
byte[] mbyte = new byte[];
int allmybyte = (int)mbyte.Length;
int startmbyte = ;
while (allmybyte > )
{
int m = str.Read(mbyte, startmbyte, allmybyte);
if (m == )
break;
startmbyte += m;
allmybyte -= m;
}
reader.Dispose();
str.Dispose();
string path = receivePath + System.IO.Path.GetFileName(URLAddress);
FileStream fstr = new FileStream(path, FileMode.OpenOrCreate, FileAccess.Write);
fstr.Write(mbyte, , startmbyte);
fstr.Flush();
fstr.Close();
原文链接
相关连接 C#实现文件下载的几种方式