当前位置: 代码迷 >> Windows Mobile >> WM 下载程序判断文件是否存在解决思路
  详细解决方案

WM 下载程序判断文件是否存在解决思路

热度:161   发布时间:2016-04-25 07:39:10.0
WM 下载程序判断文件是否存在
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);


------解决方案--------------------
是否被锁?
------解决方案--------------------
你怎么确认是死了? 是不是文件太大?
  相关解决方案