Contents - Index - Top


OnDownloadStarting

Interface AntView 

 

Type: Event

Parameters: Boolean Cancel Boolean Handled AntViewDownloadOperation DownloadOperation String ResultPath String ResultFile

 

 

Event that is raised before a download starts so that you can anticipate on the download of the file which is about to start.

 

Get/Set Cancel. By setting Cancel to True you cancel the download before it starts, the default is false.

 

Get/Set Handled. By setting Handled to True, the default download dialog is not shown.

 

DownloadOperation is of type AntViewDownloadOperation and can be used to track and manage the download process. This is a reference counted ActiveX object, which means that the object is out of scope (destroyed) if you don't assign it to another object by the end of this event. See below for an example in VB6 where we assign the object so that it persists. This way we are able to use the events that the AntViewDownloadOperation interface provides so that we can track our downloads.

 

The ResultPath parameter is by default set with the full path of the file you are trying to download. It will use the default download location for the file path and the last character is the directory separator character ("\").

You can set the ResultPath to a different absolute path to change the location of the downloaded file. This cannot be a relative path, it has to be a full path. If the folder does not yet exist, then the WebView2 control will try to create it. It is not required to put a directory separator character at the end of the path.

If you only change the directory, then make sure that the ResultFile parameter is not empty, or it still might not save anything.

 

The ResultFile parameter is by default set with the filename of the file you are trying to download. If needed you can override the name of the file here with a name of your own choice. The filename should not include the path. If the file already exists at the original ResultPath location, then it will be suffixed with "(n)" where n is incremental. Eg. if file "C:\Users\Wil\Downloads\badssl.com-client.p12" exists and you download that file again then it will change the filename to "badssl.com-client (1).p12"

 

More details can be found at the Microsoft .Net interface: CoreWebView2.DownloadStarting.

 

VB6 example code:

Private WithEvents DL As AntViewAx.AntViewDownloadOperation

 

Private Sub AntView_OnDownloadStarting(Cancel As Boolean, Handled As Boolean, ByVal DownloadOperation As AntViewAx.IAntViewDownloadOperation, ResultPath As String, ResultFileName As String)

  ' When the download operation begins, set the DownloadOperation object into the DL variable

  Set DL = DownloadOperation

End Sub

 

Private Sub DL_OnBytesReceivedChanged()

  Debug.Print "DL_OnBytesReceivedChanged"

  Debug.Print "Bytes Total Hex: " & DL.TotalBytesToReceiveHex

  Debug.Print "Bytes Received Hex: " & DL.BytesReceivedHex

End Sub

 

Private Sub DL_OnEstimatedEndTimeChanged()

  Debug.Print "DL_OnEstimatedEndTimeChanged: " & DL.EstimatedEndTime

End Sub

 

Private Sub DL_OnStateChanged()

  Debug.Print "DL_OnStateChanged: " & DL.State

End Sub

 

In the example above the DownloadOperation object is assigned for each download. If you want to release the object before the application terminates then you could track that in the OnStateChanged event. 

In VB6 you can release the object via Set DL = nothing.

 

Introduced in AntView release 1.1.164

 


AntView - The MS Edge WebView2 ActiveX control Date last changed: 09/25/2024