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

on the above line i am getting this exception

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 Settings\agordon\My Documents\Visual Studio 2008\Projects\GenerateWorklists\GenerateWorklists\Form1.cs:line 603 at WindowsFormsApplication1.Form1.btnProcess_Click(Object sender, EventArgs e) in C:\Documents and Settings\agordon\My Documents\Visual Studio 2008\Projects\GenerateWorklists\GenerateWorklists\Form1.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 Settings\agordon\My Documents\Visual Studio 2008\Projects\GenerateWorklists\GenerateWorklists\Program.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:

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.

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

Tim Lloyd
  • 37,954
  • 10
  • 100
  • 130
JOE SKEET
  • 7,950
  • 14
  • 48
  • 64

3 Answers3

1

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);  

now we can access DocumentText with no problems

dont forget to import mshtml as a reference

JOE SKEET
  • 7,950
  • 14
  • 48
  • 64
0

I too found it strange that the web browser control was throwing an exception related to file access, when I was loading a page from the web.

When looking into this, I noticed something strange: This error is far less common when the temporary internet files have recently been cleared.

I modified my application so that it clears the temporary internet files automatically when the application starts, which was enough to resolve 90% of these errors.

My code for cleaning the temporary internet files is below... I don't think this will work on all operating systems - there may be a better way - but this suits my needs because it works on Server 2008.

(my code is in vb.net, but the c# version shouldn't be too hard to figure out.)

        'start cleaning the temporary internet files
        Dim clearFilesProcess As Process = System.Diagnostics.Process.Start("rundll32.exe", "InetCpl.cpl,ClearMyTracksByProcess 255")

        'wait for the temporary internet files to be deleted
        While Not (clearFilesProcess.HasExited)
            System.Threading.Thread.Sleep(200)
        End While
Allen
  • 927
  • 8
  • 19
0

Try webBrowser1.Document.Body.InnerText.

SLaks
  • 868,454
  • 176
  • 1,908
  • 1,964