The specified path may be provided as either a file:// URL or a
local file system path. If a file:// URL is given, it will be
converted to a local path before use. Environment variables enclosed
in percent signs (such as %TEMP%) are expanded automatically.
If the path refers to an existing directory rather than a file name, the
original file's base name is preserved and the file will be created in
that directory. This allows applications to easily redirect a download
into a specific folder without changing the file name.
The method always normalizes the provided path. If a relative
path is specified, it is resolved against the current working
directory of the process. Because this can lead to unpredictable
results in multithreaded applications, it is strongly recommended that
applications always provide absolute paths. By default, downloaded
files are typically stored in the current user's Downloads folder.
Several restrictions are enforced on the path to help ensure safety
and compatibility. Device names such as CON, PRN,
or NUL are not permitted. Downloads cannot be redirected
into system folders such as the Windows folder or Program File folder.
The path cannot contain reserved characters, and files that are marked
as read-only will not be overwritten. If any of these conditions are
detected, the method will fail with an error.
This method can only be called within a handler for the
WEBVIEW_EVENT_DOWNLOAD_STARTING event. Once the download has
begun, the local file path cannot be changed. If you wish to move the
file after it has been downloaded, you can use the
GetDownloadPath method to obtain its current location and
then use a Win32 function like MoveFileEx to move the file to a new
folder.
Note that you should avoid showing modal dialogs such as the common
"Save File" dialog within event handlers. Because the browser
events are raised within the context of the WebView2 UI thread,
displaying a dialog asking the user for a new download location
can prevent the control from processing its internal message loop,
potentially leading to stalled downloads.