MicrosoftEdge/WebView2Feedback

How can I change default EBWebView folder path.

Closed this issue · 5 comments

When we use WebView2 in Windows form application and first time run it, It could create exe-name.webview2/EBWebView folder in the executable file path. How can I set the new location of it before first running.

You can set the user data folder in the CoreWebView2Environment.CreateAsync method. The second parameter is the user data folder, and the other two parameters may be null to use their default values.

You can then have the WinForms WebView2 use your CoreWebView2Environment to create its CoreWebView2 by calling the WebView2.EnsureCoreWebView2Async method.

However, you must call EnsureCoreWebView2Async before you set the WebView2.Source property as setting that property implicitly causes initialization to begin with a default CoreWebView2Environment. This is likely how you were seeing the default user data folder getting created.

You can read more about WinForms WebView2 control initialization in the WebView2.EnsureCoreWebView2Async documentation.

And for reference, here are some more notes on the user data folder.

Can you make a property for this in the WebView2 control? It would be better to set the path after the InitializeComponent method.
Like this
InitializeComponent();
webView21.UserDataFolder=Path.GetTempPath();

The WinForms & WPF WebView2 controls have a CreationProperties property you can also use to more easily set the UserDataFolder via the designer or xaml.

Why not have a more sensible default though, like for example, the application data folder where .NET automatically stores other stuff (like the application settings) ?

@hugoam We are currently investigating to see if we can pick a different default that will automatically work in more scenarios. I believe we are tracking this in #297.