C#中的网页浏览器FileNotFoundException异常?异常、网页浏览器、FileNotFoundException

2023-09-02 02:05:29 作者:你是猴子请来的救兵么

if (webBrowser1.DocumentText.IndexOf("Page: 1") != -1)

在上面的行我收到此异常

on the above line i am getting this exception

System.IO.FileNotFoundException是   未处理消息=系统无法   找到指定的文件。 (例外   来自HRESULT:0x80070002)   来源=System.Windows.Forms的   堆栈跟踪:          在System.Windows.Forms.UnsafeNativeMethods.IPersistStreamInit.Save(的IStream   PSTM,布尔fClearDirty)          在System.Windows.Forms.WebBrowser.get_DocumentStream()          在System.Windows.Forms.WebBrowser.get_DocumentText()          在WindowsFormsApplication1.Form1.GenerateETGWorklists()   在C: Documents和   设置 agordon 我的文档 Visual   工作室   2008 项目 GenerateWorklists GenerateWorklists Form1.cs中:行   603          在WindowsFormsApplication1.Form1.btnProcess_Click(对象   发件人,EventArgs e)在C:文件   和设置 agordon 我   文档 Visual Studio中   2008 项目 GenerateWorklists GenerateWorklists Form1.cs中:行   55          在System.Windows.Forms.Control.OnClick(EventArgs的   E)          在System.Windows.Forms.Button.OnClick(EventArgs的   E)          在System.Windows.Forms.Button.OnMouseUp(MouseEventArgs   mevent)          在System.Windows.Forms.Control.WmMouseUp(消息&安培;   男,MouseButtons按钮,点击的Int32)          在System.Windows.Forms.Control.WndProc(消息&安培;   M)          在System.Windows.Forms.ButtonBase.WndProc(消息&安培;   M)          在System.Windows.Forms.Button.WndProc(消息&安培;   M)          在System.Windows.Forms.Control.ControlNativeWindow.OnMessage(消息&安培;   M)          在System.Windows.Forms.Control.ControlNativeWindow.WndProc(消息&安培;   M)          在System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr的   的hWnd,味精的Int32,IntPtr的WPARAM,IntPtr的   LPARAM)          在System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG和放大器;   MSG)          在System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32   dwComponentID,的Int32原因,的Int32   pvLoopData)          在System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(的Int32   因此,ApplicationContext的情况下)          在System.Windows.Forms.Application.ThreadContext.RunMessageLoop(的Int32   因此,ApplicationContext的情况下)          在System.Windows.Forms.Application.Run(表   MainForm的)          在WindowsFormsApplication1.Program.Main()   在C: Documents和   设置 agordon 我的文档 Visual   工作室   2008 项目 GenerateWorklists GenerateWorklists 的Program.cs:行   18          在System.AppDomain._nExecuteAssembly(议会   装配,字串[] args)          在System.AppDomain.ExecuteAssembly(字符串   assemblyFile,证据   assemblySecurity,字串[] args)          在Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()          在System.Threading.ThreadHelper.ThreadStart_Context(对象   州)          在System.Threading.ExecutionContext.Run(执行上下文   执行上下文,ContextCallback   回调,对象的状态)          在System.Threading.ThreadHelper.ThreadStart()   的InnerException:

System.IO.FileNotFoundException was unhandled Message="The system cannot find the file specified. (Exception from HRESULT: 0x80070002)" Source="System.Windows.Forms" StackTrace: at System.Windows.Forms.UnsafeNativeMethods.IPersistStreamInit.Save(IStream pstm, Boolean fClearDirty) at System.Windows.Forms.WebBrowser.get_DocumentStream() at System.Windows.Forms.WebBrowser.get_DocumentText() at WindowsFormsApplication1.Form1.GenerateETGWorklists() in C:Documents and SettingsagordonMy DocumentsVisual Studio 2008ProjectsGenerateWorklistsGenerateWorklistsForm1.cs:line 603 at WindowsFormsApplication1.Form1.btnProcess_Click(Object sender, EventArgs e) in C:Documents and SettingsagordonMy DocumentsVisual Studio 2008ProjectsGenerateWorklistsGenerateWorklistsForm1.cs:line 55 at System.Windows.Forms.Control.OnClick(EventArgs e) at System.Windows.Forms.Button.OnClick(EventArgs e) at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent) at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks) at System.Windows.Forms.Control.WndProc(Message& m) at System.Windows.Forms.ButtonBase.WndProc(Message& m) at System.Windows.Forms.Button.WndProc(Message& m) at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m) at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m) at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam) at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg) at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData) at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context) at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context) at System.Windows.Forms.Application.Run(Form mainForm) at WindowsFormsApplication1.Program.Main() in C:Documents and SettingsagordonMy DocumentsVisual Studio 2008ProjectsGenerateWorklistsGenerateWorklistsProgram.cs:line 18 at System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args) at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args) at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly() at System.Threading.ThreadHelper.ThreadStart_Context(Object state) at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state) at System.Threading.ThreadHelper.ThreadStart() InnerException:

这个又是什么意思?我没有得到这个错误,昨天和今天得到它。网页打开没有问题,文本页:1 肯定是存在的。

what is the meaning of this? i did not get this error yesterday and getting it today. the webpage opens no problem and the text Page: 1 is definitely there.

下面是一个类似的问题还没有解决之道 的http://bytes.com/topic/c-sharp/answers/657812-webbrowser-documenttext-getting-problem

here is a similar issue also without solution http://bytes.com/topic/c-sharp/answers/657812-webbrowser-documenttext-getting-problem

推荐答案

这是一个已知的bug和微软没有为VS2008至少做任何事情。这里有一个修复:

this is a known bug and microsoft doesn't do anything about it for vs2008 at least. here's a fix:

String lastsource = ((mshtml.HTMLDocumentClass)(((webBrowser1.Document.DomDocument)))).documentElement.innerHTML;
            webBrowser1.Document.OpenNew(true);
            webBrowser1.Document.Write(lastsource);  

现在我们可以访问 DocumentText ,没有任何问题。

now we can access DocumentText with no problems

不要忘记导入 MSHTML 作为参照