环境: VS2005  XP我的程序不知怎么回事,大多数情况下编译后能正确执行,但有时候会在执行时遇到System.IO.FileNotFoundException异常:
System.IO.FileNotFoundException 系统找不到指定的文件。 (异常来自 HRESULT:0x80070002)异常提示信息到此为止,我也不知道是找不到啥文件。不过不用修改代码,重新编译后,程序就能正常执行了(或者重启机器也行)。请大虾们指点一下,thanks!
=================================
附带关于我项目的一些信息项目名称:SaveWebPage
using System;
using System.Collections.Generic;
using System.Collections;
using System.IO;
using System.Text;
using System.Windows.Forms;
using mshtml;
using System.Net;
using System.Net.Cache;
using System.Text.RegularExpressions;
using System.Threading;异常出现在执行:string dt = this.WebBrowser1.DocumentText;时。

解决方案 »

  1.   

            public byte[] CreateMhtData()
            {
                SaveHTMLDocument(ControlObj.Document);            MemoryStream ms = new MemoryStream();
                string boundary = "\r\n\r\n------=_NextPart_000_0000_01CA095D.30E12370\r\n";
                string end = "\r\n\r\n------=_NextPart_000_0000_01CA095D.30E12370--";            string head = "From: <由 InfiKeeper 保存>\r\n";
                head += ("Subject: " + ControlObj.DocumentTitle + "\r\n");
                head += "Date: " + DateTime.Now.Date.ToString() + "\r\n";
                head += "MIME-Version: 1.0\r\n";
                head += "Content-Type: multipart/related;\r\n";
            head += "  type=\"text/html\";\r\n";
            head += "  boundary=\"----=_NextPart_000_0000_01CA095D.30E12370\"\r\n";
                head += "\r\n";            byte[] b0 = System.Text.Encoding.GetEncoding("GB2312").GetBytes(head);   
                ms.Write(b0,0,b0.Length);            //以下获取CharSet的代码来自网络
                string dt = "";
                try
                { dt = this.ControlObj.DocumentText; }
                catch (System.IO.FileNotFoundException e_)
                { throw new SaveWebPageException(e_.Message,980003); }            Match charSetMatch = Regex.Match(dt, "<meta([^<]*)charset=([^<]*)\"", RegexOptions.IgnoreCase | RegexOptions.Multiline); 
                string CharSet = charSetMatch.Groups[2].Value; 出错前后代码
      

  2.   

            public byte[] CreateMhtData()
            {
                SaveHTMLDocument(ControlObj.Document);            MemoryStream ms = new MemoryStream();
                string boundary = "\r\n\r\n------=_NextPart_000_0000_01CA095D.30E12370\r\n";
                string end = "\r\n\r\n------=_NextPart_000_0000_01CA095D.30E12370--";            string head = "From: <由 InfiKeeper 保存>\r\n";
                head += ("Subject: " + ControlObj.DocumentTitle + "\r\n");
                head += "Date: " + DateTime.Now.Date.ToString() + "\r\n";
                head += "MIME-Version: 1.0\r\n";
                head += "Content-Type: multipart/related;\r\n";
            head += "  type=\"text/html\";\r\n";
            head += "  boundary=\"----=_NextPart_000_0000_01CA095D.30E12370\"\r\n";
                head += "\r\n";            byte[] b0 = System.Text.Encoding.GetEncoding("GB2312").GetBytes(head);   
                ms.Write(b0,0,b0.Length);            //以下获取CharSet的代码来自网络
                string dt = "";
                try
                { dt = this.ControlObj.DocumentText; }
                catch (System.IO.FileNotFoundException e_)
                { throw new SaveWebPageException(e_.Message,980003); }            Match charSetMatch = Regex.Match(dt, "<meta([^<]*)charset=([^<]*)\"", RegexOptions.IgnoreCase | RegexOptions.Multiline); 
                string CharSet = charSetMatch.Groups[2].Value;             string html = "------=_NextPart_000_0000_01CA095D.30E12370\r\n";
                html += "Content-Type: text/html;\r\n";
                html += ("  charset=" + "\"" + CharSet +"\"" + "\r\n" );
            html += "Content-Transfer-Encoding: quoted-printable\r\n";
                html += ("Content-Location: " + this.URL +"\r\n\r\n");            byte[] b1 = System.Text.Encoding.GetEncoding("GB2312").GetBytes(html);
                ms.Write(b1, 0, b1.Length);            bool charChange = false;
                if (string.Equals(CharSet, "unicode"))
                { 
                    CharSet = "utf-16";
                    charChange = true;
                }            StreamReader sr = new StreamReader(this.ControlObj.DocumentStream, System.Text.Encoding.GetEncoding(CharSet), true);
                string sHtml = sr.ReadToEnd();            if (charChange)
                {
                    CharSet = "utf-8";
                    sHtml.Replace("charset=unicode", "charset=utf-8");
                    byte[] temp1 = System.Text.Encoding.GetEncoding("utf-16").GetBytes(sHtml);
                    byte[] temp2 = Encoding.Convert(System.Text.Encoding.GetEncoding("utf-16"), System.Text.Encoding.GetEncoding("utf-8"), temp1);
                    sHtml = System.Text.Encoding.GetEncoding("utf-8").GetString(temp2);
                }            string sss = Encode(sHtml, CharSet);
                byte[] temp10 = System.Text.Encoding.GetEncoding(CharSet).GetBytes(sss); 
                ms.Write(temp10, 0, temp10.Length);            for (int i = 0; i < ContentParts.Count;++i )
                {
                    byte[] bb = System.Text.Encoding.GetEncoding("GB2312").GetBytes(boundary);   
                    byte[] dd = ((ContentPart)ContentParts[i]).GetContent();
                    ms.Write(bb, 0, bb.Length);
                    ms.Write(dd,0,dd.Length);
                }            byte[] be = System.Text.Encoding.GetEncoding("GB2312").GetBytes(end); 
                ms.Write(be, 0, be.Length);
                ms.WriteByte(13);
                ms.Position = 0;            byte[] result = Tools.StreamToBytes(ms);
                return result;
            }//end fun
      

  3.   

    我用你的代码没有任何问题,你的web控件指向哪个地址?
      

  4.   

    没看到webbrower,应该是通过WebBrowser.DocumentText,再获取页面文件时问题