Can not find visit a absolute path local file whith webview2
Posted: Fri Aug 23, 2024 1:23 am
Hi Forum,
I have a program that uses webview2, which loads a local HTML file. Since loading local HTML files requires an absolute path, I obtained the absolute path in the program and displayed it normally.
But when I packaged all the files together, webview2 couldn't display it anymore.
Program directory structure:
- FormMain.cs
- wwwroot
- - index.html
Load the code for the HTML section:
string exePath = AppDomain.CurrentDomain.BaseDirectory;
string relativePath = "wwwroot/index.html";
string path = System.IO.Path.Combine(exePath, relativePath);
WebView21.Source = new Uri(@"file:///" + path);
I guess after packaging it into an exe, webview2 cannot load the contents of wwwroot in the current folder.
May I ask if any relevant configurations need to be made during packaging to solve this problem?
I have a program that uses webview2, which loads a local HTML file. Since loading local HTML files requires an absolute path, I obtained the absolute path in the program and displayed it normally.
But when I packaged all the files together, webview2 couldn't display it anymore.
Program directory structure:
- FormMain.cs
- wwwroot
- - index.html
Load the code for the HTML section:
string exePath = AppDomain.CurrentDomain.BaseDirectory;
string relativePath = "wwwroot/index.html";
string path = System.IO.Path.Combine(exePath, relativePath);
WebView21.Source = new Uri(@"file:///" + path);
I guess after packaging it into an exe, webview2 cannot load the contents of wwwroot in the current folder.
May I ask if any relevant configurations need to be made during packaging to solve this problem?