public bool Download(string URL, string Dir)
{
WebClient client = new WebClient();
string fileName = URL.Substring(URL.LastIndexOf("/") + 1); //被下载的文件名
string Path = Dir+fileName; //另存为的绝对路径+文件名
try
{
WebRequest myre = WebRequest.Create(URL);
client.DownloadFile(URL, fileName);
FileStream fs = new FileStream(fileName, FileMode.Open, FileAccess.Read);
BinaryReader r = new BinaryReader(fs);
byte[] mbyte = r.ReadBytes((int)fs.Length);
FileStream fstr = new FileStream(Path, FileMode.OpenOrCreate, FileAccess.Write);
fstr.Write(mbyte, 0, (int)fs.Length);
fstr.Close();
}
catch (Exception e)
{
MessageBox.Show(e.Message, "Error");
return false;
}
return true;
}