//下載文件1 public static void downfile(string downloadUrl,string filename,string filepath) { HttpWebRequest hwr = (HttpWebRequest)WebRequest.Create(downloadUrl); hwr.Timeout = 15000; HttpWebResponse hwp = (HttpWebResponse)hwr.GetResponse(); Stream ss = hwp.GetResponseStream(); byte[] buffer = new byte[10240]; if (!Directory.Exists(filepath)) { Directory.CreateDirectory(filepath); } FileStream fs = new FileStream( string.Format(filepath + @"\" + filename), FileMode.Create); try { int i; while ((i = ss.Read(buffer, 0, buffer.Length)) > 0) { fs.Write(buffer, 0, i); } fs.Close(); ss.Close(); } catch (Exception) { throw; } }