if (webBrowser1.DocumentText.IndexOf(\"Page: 1\") != -1)
on the above line i am getting this exception
System.IO.FileNotFoun
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
Try webBrowser1.Document.Body.InnerText
.
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