c# filenotfoundexception on webbrowser?

前端 未结 3 1498
醉话见心
醉话见心 2020-12-12 03:19
if (webBrowser1.DocumentText.IndexOf(\"Page: 1\") != -1)

on the above line i am getting this exception

System.IO.FileNotFoun

相关标签:
3条回答
  • 2020-12-12 03:47

    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
    
    0 讨论(0)
  • 2020-12-12 03:57

    Try webBrowser1.Document.Body.InnerText.

    0 讨论(0)
  • 2020-12-12 03:59

    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 讨论(0)
提交回复
热议问题