DownloadStateChanged事件

当文件下载状态发生变化时触发本事件,例如下载暂停、恢复、取消、失败、成功等。

属性名 类型 说明
Uri String 当前下载资源的原始下载地址URL
MimeType String 返回下载内容的类型
ResultFilePath String 返回文件名,包括路径。
State CoreWebView2DownloadState CoreWebView2DownloadState类型,用于表示下载状态,包括三个值:

Completed:    下载成功
Interrupted:  暂停或失败
InProgress:   正在下载

BytesReceived Long 已经接收的字节数
TotalBytesToReceive Long 要接受的字节数,也就是文件大小
CanResume Boolean 停止的下载是否可以恢复,如果返回True,表示下载处于暂停状态,如果返回False,表示下载已经取消或失败
DownloadOperation CoreWebView2DownloadOperation 表示本次下载任务,可用于获取关于本次下载任务的更多信息(一般用户用不着)
GetDeferral 方法 延迟提交事件(一般用户用不着)

示例

例如要跟踪下载状态,可以在DownloadStateChanged事件加上代码:

If e.State = CoreWebView2DownloadState.Completed Then
   
Dim str As String = "url来源:" & e.DownloadOperation.Uri & vbCrLf
    str = str &
"存储路径:" & e.DownloadOperation.ResultFilePath & vbCrLf
    str = str &
"文件大小:" & e.DownloadOperation.TotalBytesToReceive
    MessageBox.Show(str,
"下载成功")
ElseIf
e.State = CoreWebView2DownloadState.Interrupted Then
   
If e.CanResume Then
       
Dim per As String = Format(e.BytesReceived / e.TotalBytesToReceive, "0.00%")
        MessageBoxA.Show(
"下载暂停,已经完成" & per)
   
Else
        MessageBoxA.Show(
"下载取消或失败")
       
'可以通过e.DownloadOperation.InterruptReason获取失败原因
   
End If
ElseIf
e.State = CoreWebView2DownloadState.InProgress Then
    MessageBoxA.Show(
"下载继续")
End
If

 


本页地址:http://www.foxtable.com/webhelp/topics/6990.htm