下載 AP 檔案到 Client 的方法?

 

using System.Net;           // WebRequest

private bool DownLoad(string wFileName,string LocalFileName)
{
   string FileName = Path.GetFileName(wFileName);
   if (PublicFunction.IsRunTime())
   {
      string URL = "http://" + LRClient.APServer + "/LRERP/Export/" + FileName;
      try
      {
         WebRequest RST = WebRequest.Create(URL);
         WebClient wc = new WebClient();
         wc.Credentials = CredentialCache.DefaultCredentials;
         wc.DownloadFile(URL, LocalFileName);
         return true;
      }
      catch(Exception ex)
      {
        PublicForms.RunfrmMsg("Error",ex.Message);
         return false;
      }
   }
   else
   {
      File.Copy(wFileName,LocalFileName,true);
      return true;
   }
}

沒有留言: