c# filenotfoundexception on webbrowser?

前端 未结 3 1605
醉话见心
醉话见心 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
    

提交回复
热议问题