Customize the UserDataFolder
At runtime, WebView2 needs a working folder for storing data used during the session. By default, a folder will be created in the same folder as your executable file, called
MyApp.Exe.WebView2). If this folder cannot be created, the WebView2 control will not work (you can catch the controls Error event to determine this at runtime).
This default behaviour is not always appropriate. For example, if you’re creating an Addin for Microsoft Access, then you almost certainly will not be allowed to create a folder called
MSACCESS.EXE.WebView2 in the Office sub folder of your systems Program Files folder.
It is HIGHLY recommended that you override the default behaviour, and instead provide a path that is considered to be safe to use for storing such data. To override the UserDataFolder path at runtime, handle the Create event of the WebView2 control. See the example in
Sample 9. ActiveX Control WebView2 + Monaco here, where we use the
%APPDATA%\Local system path:
EnvironmentOptions.UserDataFolder property to a string containing the output path to use (folder will be created if necessary).