C# has a WebBrowse control, but it is based on IE and is not HTML5 friendly. In order to support HTML5 perfectly, Google's embedded Chrome engine is required. The cefsharp package packs the Chome engine. I tried the following program. The problem encountered is how to access local documents. The method introduced on the Internet is a bit outdated.
To be able to access local files, please use the following code
// Allow the use of local resources in the browser BrowserSettings browserSettings = new BrowserSettings(); = ; = ; = browserSettings;
However, the new cefsharp version does not support the two properties of FileAccessFromFileUrls and UniversalAccessFromFileUrls. The website introduces the use of the command flag (--allow-universal-access-from-files) and (allow-file-access-from-files). I've tried adding
("allow-universal-access-from-files","1"); ("allow-file-access-from-files","1");
I added these two switches to the Chrome properties in the computer, and it was all the time, and it was fine to remove the above two statements. Don't know why. Below is the code that can be run. For reference by those who need it
using System; using ; using ; using ; using ; using ; using ; using ; using ; using CefSharp; using ; using ; using ; namespace WebkitTest { public partial class Form1 : Form { ChromiumWebBrowser CWebBrowser; public void InitializeChromium() { CefSettings settings = new CefSettings(); // ("allow-universal-access-from-files","1"); // ("allow-file-access-from-files","1"); (settings); // Create a browser component CWebBrowser = new ChromiumWebBrowser("File://E:/yao2022/HMI/views/"); // Add it to the form and fill it to the form window. splitContainer1.(CWebBrowser); = ; // ("File://E:/yao2022/HMI/views/"); } public Form1() { InitializeComponent(); InitializeChromium(); } private void btn_Browse_Click(object sender, EventArgs e) { (""); } private void btn_load_Click(object sender, EventArgs e) { (); } } }
This is the end of this article about the use of C# cefSharep controls. For more related C# cefSharep content, please search for my previous articles or continue browsing the related articles below. I hope everyone will support me in the future!