//下载文件
//downlaodUrl 系统路径如:http://xxx.xxx.xxx/UpFile/kaoqin.doc
//fileName 自定义文件名字加后缀(如:考勤.doc)
//filePath 文件存放路径如: E:\2016\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; } }

 

相关文章:

  • 2021-07-27
  • 2021-08-16
  • 2021-07-31
  • 2022-02-01
  • 2021-07-26
  • 2021-12-17
猜你喜欢
  • 2021-06-05
  • 2021-08-03
  • 2021-09-28
  • 2022-12-23
相关资源
相似解决方案