DataFolder Property  
 

Gets and sets the path to the user data folder used by this instance.

Syntax

object.DataFolder [= value ]

Remarks

The User Data Folder (UDF) is the WebView2 profile directory that Chromium uses to persist browsing state for this instance. It contains the browser cache, cookies, localStorage data, service worker state, visited link history, site permissions, and other profile data. Each distinct folder path corresponds to a distinct browser profile. Multiple WebView2 instances that point to the same folder will share the same profile (and therefore share cookies, storage, and authentication state). Using different folder paths isolates profiles.

The user data folder is chosen when the WebView instance is created and cannot be changed afterwards. You should set this property value in design mode or within an event handler for the Initialize event. This property cannot be changed after that point. If your application needs to switch profiles (for example, to use a different folder), you must destroy the current control instance and create a new one with the desired folder.

If your application does not specify a folder or uses an empty string as the folder path, the control creates a unique per-session folder under the current user's local profile. This is an ephemeral profile that is not intended to be reused across browser instances. By default, this temporary folder is removed when the control is unloaded; if the process terminates unexpectedly, the folder may remain and can be safely deleted later.

In contrast, specifying an explicit, persistent folder (for example, a subdirectory under %LocalAppData%\WebView\YourApp) gives you a shared profile that persists across sessions and can be reused by multiple WebView2 instances to enable single sign-on, shared cookies, and faster subsequent navigations due to caching. Use this approach when you want consistent, long-lived browser state.

The reported folder path is always an absolute, normalized local path. Environment variables in the path you supply at creation time are expanded; forward slashes are normalized to backslashes and relative names are resolved beneath the current user's local application data folder. The control rejects invalid or unsafe locations (e.g.: device names, system directories, UNC or extended path prefixes, or root drive targets) and will create intermediate directories as needed for valid paths.

Important: The user data folder is managed internally by the the WebView2 runtime, and your application should never attempt to modify, move, or delete any of the files it contains while a browser instance is active. The contents are in use by the rendering engine and interfering with them can result in data corruption or unexpected behavior. If you need to remove or relocate a profile, ensure that all browser instances using that folder have been completely closed. If you want to delete certain data, such as cookies or the browser history, use the functions provided specifically for that purpose.

You can check the value of this property at any time after the instance has been created to discover which profile directory is in use.

Data Type

String

See Also

InPrivate Property, Initialize Event