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

WM 上载程序判断文件是否存在

热度:6420   发布时间:2013-02-26 00:00:00.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;
  相关解决方案