Not able to set ResultFilePath

Post Reply
SpringerRider
Posts: 8
Joined: Tue Sep 13, 2022 7:26 pm

Not able to set ResultFilePath

Post by SpringerRider »

I am using the download feature as a file drop. I would like to manage the directory the files are dropped.
I'm using the miniBrowser Demo as a prototype.

Though I want to manage the download directory myself, right now it is always going to my Downloads directory. Even when I set the directory under Edge Settings to a different directory.

It seems as if it is hard-coded.

Code: Select all

procedure TMiniBrowserFrm.WVBrowser1DownloadStarting(Sender: TObject; const aWebView: ICoreWebView2; const aArgs: ICoreWebView2DownloadStartingEventArgs);
var
  TempArgs : TCoreWebView2DownloadStartingEventArgs;
begin
  TempArgs := TCoreWebView2DownloadStartingEventArgs.Create(aArgs);
  TempArgs.ResultFilePath:='D:\EdgeDownloads\';
  if assigned(TempArgs.DownloadOperation) and not(assigned(FDownloadOperation)) then
    begin
      FDownloadOperation := TCoreWebView2DownloadOperation.Create(TempArgs.DownloadOperation, GetNextDownloadID);
      FDownloadOperation.AddAllBrowserEvents(WVBrowser1);
      // We hide the download window

      TempArgs.Handled := true;
    end;

  FreeAndNil(TempArgs);
end;
User avatar
salvadordf
Posts: 4089
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: Not able to set ResultFilePath

Post by salvadordf »

This is what the WebView2 documentation say about ResultFilePath :
If setting the path, the host should ensure that it is an absolute path, including the file name, and that the path does not point to an existing file. If the path points to an existing file, the file will be overwritten. If the directory does not exist, it is created.
https://docs.microsoft.com/en-us/microsoft-edge/webview2/reference/win32/icorewebview2downloadstartingeventargs?view=webview2-1.0.1343.22#get_resultfilepath

Try adding this code :

Code: Select all

TempArgs.ResultFilePath := 'D:\EdgeDownloads\file.txt';
ResultFilePath must be an absolute path to a writable directory and it must include the file name.
SpringerRider
Posts: 8
Joined: Tue Sep 13, 2022 7:26 pm

Re: Not able to set ResultFilePath

Post by SpringerRider »

thanks. that worked.
GaryShelton
Posts: 2
Joined: Tue Jan 24, 2023 10:19 pm

Re: Not able to set ResultFilePath

Post by GaryShelton »

Salvadordf,

I have used the above and it works, however I get memory leaks for the 3 added events from
FDownloadOperation.AddAllBrowserEvents(WVBrowser1);

How/when do I clean these up.

Also I do want to overwrite file location, I'm updating Geo locations, but this creates ne file with (1) appended. Anyideas on how to be sure it overwrites? Alternatively, I could save and copy myself, but I would need to know when file is finished downloading.

Thanks in advance
Gary
GaryShelton
Posts: 2
Joined: Tue Jan 24, 2023 10:19 pm

Re: Not able to set ResultFilePath

Post by GaryShelton »

Not sure what I did but all is well..Thanks
Post Reply