try
  {
  HttpWebRequest Myrq = (HttpWebRequest)HttpWebRequest.Create(URL);
  HttpWebResponse myrp = (HttpWebResponse)Myrq.GetResponse();
  //判断是否有这个文件,如果有这个文件就删除
  if (Directory.Exists(System.Web.HttpContext.Current.Server.MapPath(Filename + "\\client.cab")) == true)
  {
  Directory.Delete(System.Web.HttpContext.Current.Server.MapPath(Filename + "\\client.cab"), true);
  }
  long totalBytes = myrp.ContentLength;
  if (Prog != null)
  {
  Prog.Maximum = (int)totalBytes;
  }
  System.IO.Stream st = myrp.GetResponseStream();
  System.IO.Stream so = new FileStream(Filename, FileMode.Append, FileAccess.Write);
  long totalDownloadedByte = 0;
  byte[] by = new byte[1024];
  int osize = st.Read(by, 0, (int)by.Length);
  while (osize > 0)
  {
  totalDownloadedByte = osize + totalDownloadedByte;
  Application.DoEvents();
  so.Write(by, 0, osize);
  Prog.Value = (int)totalDownloadedByte;
  osize = st.Read(by, 0, (int)by.Length);
  percent = (float)totalDownloadedByte / (float)totalBytes * 100;
  label1.Text = "更新进度" + percent.ToString() + "%";
  System.Windows.Forms.Application.DoEvents();
  }
  so.Close();
  st.Close();
  MessageBox.Show("下载完成", "下载提示:", MessageBoxButtons.YesNo, MessageBoxIcon.Asterisk, MessageBoxDefaultButton.Button3);
  System.Diagnostics.Process.Start("client.cab", Filename);
  Application.Exit();
  }执行下面这就死了呢 //判断是否有这个文件,如果有这个文件就删除
  if (Directory.Exists(System.Web.HttpContext.Current.Server.MapPath(Filename + "\\client.cab")) == true)
  {
  Directory.Delete(System.Web.HttpContext.Current.Server.MapPath(Filename + "\\client.cab"), true);
 
 
 

解决方案 »

  1.   

    又落底了
    File.Exists("~client.cab"))
    {
    File.Delete("~client.cab"))
    }
    这样也不成 ,大侠们
      

  2.   

    试试这样string path = System.IO.Path.GetFullPath(System.Web.HttpContext.Current.Server.MapPath("~/client.cab"));
    if(File.Exists(path)))
    {
        File.Delete(path))
    }
      

  3.   

    System.Web.HttpContext.Current.Server.MapPath 执行这个就死机了
      

  4.   

    解决了
    string path = System.IO.Path.GetFullPath("\\client);这样就可以了