1
votes
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

3
What is the WebBrowser displaying?SLaks
you need to check that the file is still in the place that your code is calling it from, that no other process has that file in use and that the privelages still allow this writing and reading of filesDaniel Casserly
@daniel there's no file yet. it gets it from the webpageJOE SKEET
@JOE, Are you sure you have IE installed with all its core files and dlls?deadlock
@dead this was working yesterday fineJOE SKEET

3 Answers

1
votes

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

0
votes

Try webBrowser1.Document.Body.InnerText.

0
votes

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