c#保存远程文件到本地

  ///, & lt; summary>///,保存远程文件到本地///,& lt;/summary>///,& lt; param  name=" url "祝辞远程文件URL///,& lt; param  name="文件"祝辞保存的本地路径& lt;/param>///,& lt; returns> & lt;/returns>   public  bool  DownloadFile (string  url, string 文件)   {   ,,,试一试   ,,,{   ,,,,,,,(new  System.Net.WebClient ()) .DownloadFile (url、文件);   ,,,,,,,return 真实;   ,,,}   ,,,catch  {,}      ,,,return 假;   }      public  void 下载(string  strURL string  strName)   ,,,{   ,,,,,,,string  strRootDir =,“D: \ \ DownLoadRecode”;   ,,,,,,,if  (! Directory.Exists (strRootDir))   ,,,,,,,{   ,,,,,,,,,,,Directory.CreateDirectory (strRootDir);   ,,,,,,,}   ,,,,,,,WebClient  client =, new  WebClient ();   ,,,,,,,string  strFileName =, string.Empty;   ,,,,,,,string  strFileDir =, string.Empty;   ,,,,,,,string  strSavePath =, string.Empty;   ,,,,,,,string [], arrName =, strName.Split (“/?;   ,,,,,,,if  (arrName  !=, null ,,, arrName.Length 祝辞,1)   ,,,,,,,{   ,,,,,,,,,,,strFileDir =, arrName [0];   ,,,,,,,,,,,strFileName =, arrName [1];   ,,,,,,,,,,,strSavePath =, strRootDir  +,“\ \”, +, strFileDir;   ,,,,,,,,,,,if  (! Directory.Exists (strSavePath))   ,,,,,,,,,,,{   ,,,,,,,,,,,,,,,Directory.CreateDirectory (strSavePath);   ,,,,,,,,,,,}   ,,,,,,,}   ,,,,,,,   ,,,,,,,{   ,,,,,,,,,,,strFileName =, strName;   ,,,,,,,,,,,strSavePath =, strRootDir  +,“\ \ Temp”;   ,,,,,,,,,,,if  (! Directory.Exists (strSavePath))   ,,,,,,,,,,,{   ,,,,,,,,,,,,,,,Directory.CreateDirectory (strSavePath);   ,,,,,,,,,,,}   ,,,,,,,}   ,,,,,,,strSavePath  +=,“\ \”, +, strFileName;   ,,,,,,,if  (! File.Exists (strSavePath))   ,,,,,,,{   ,,,,,,,,,,,client.DownloadFile (strSavePath strURL也);   ,,,,,,,},,,,,,,,      ,,,,,,,FileInfo  xFileInfo =, new  FileInfo (strSavePath);   ,,,,,,,Response.Clear(),,,,,//清除缓冲区流中的所有内容输出   ,,,,,,,Response.ClearHeaders(),,,,,//清除缓冲区中的所有头   ,,,,,,,Response.Buffer =,假的,,,,,//设置缓冲输出为,假的   ,,,,,,,//设置输出流的,HTTP  MIME 类型为,应用程序/八进制   ,,,,,,,Response.ContentType =,“音频/x-wav”;   ,,,,,,,Response.Charset =,“GB2312”;   ,,,,,,,Response.ContentEncoding =, Encoding.UTF8;   ,,,,,,,//将,HTTP 头添加到输出流   ,,,,,,,Response.AppendHeader(“附加”,   null   null   null   null   null   null   null

c#保存远程文件到本地