Page 1 of 1

Not able to set ResultFilePath

Posted: Tue Sep 13, 2022 7:36 pm
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;

Re: Not able to set ResultFilePath

Posted: Wed Sep 14, 2022 9:14 am
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.

Re: Not able to set ResultFilePath

Posted: Fri Sep 16, 2022 4:06 pm
by SpringerRider
thanks. that worked.

Re: Not able to set ResultFilePath

Posted: Wed Jan 25, 2023 1:04 pm
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

Re: Not able to set ResultFilePath

Posted: Wed Jan 25, 2023 1:49 pm
by GaryShelton
Not sure what I did but all is well..Thanks