2017-01-19

I needed to create a program which will run a web page from the local file system. Using the WebBrowser control wasn't really an option since that uses the Trident engine which didn't support many of the things we were trying to do in the web page. I went with the latest build of CefSharp.Wpf, but that doesn't natively run local files, so it had to be modified. Fortunately, I found some posts on how to enable that feature (hereĀ and here) - however, the first link was for an older version of CefSharp, and the second link only works with static resource files. I ended up merging both concepts to get it to work.

The code below works on version 53.0.1 of CefSharp.Wpf.

First, the following two classes needed to be created:

LocalResourceHandlerFactory.cs:

LocalResourceHandler.cs:

With the above code in place, we can now load the web page from a local file. The code below assumes that the HTML files are located in a 'web' subdirectory (for example, /bin/debug/web/)

Show more