[SOLVED] Handling downloads for CEFSharp in VB.NET

I couldn't find a clear way of implementing a chrome styled downloads in CEFSharp. Help is needed!

Like +1 Dislike

Hiya [notify]ShoutOut! Technology[/notify],
Well first you'll have to create a new class called "DownloadHandler" to handle all the downloads and such, like this:

Imports CefSharp
Public Class DownloadHandler
Implements IDownloadHandler

Public Event OnBeforeDownloadFired As EventHandler(Of DownloadItem)
Public Event OnDownloadUpdatedFired As EventHandler(Of DownloadItem)

Public Sub OnBeforeDownload(browser As IBrowser, downloadItem As DownloadItem, callback As IBeforeDownloadCallback) Implements IDownloadHandler.OnBeforeDownload
    RaiseEvent OnBeforeDownloadFired(Me, downloadItem)

    If Not callback.IsDisposed Then
        Using callback
            callback.[Continue](downloadItem.SuggestedFileName, showDialog:=False)
        End Using
    End If
End Sub

Public Sub OnDownloadUpdated(browser As IBrowser, downloadItem As DownloadItem, callback As IDownloadItemCallback) Implements IDownloadHandler.OnDownloadUpdated
    RaiseEvent OnDownloadUpdatedFired(Me, downloadItem)
End Sub
End Class

And then you just create a new instance of it in the form containing the browser control itself, like this (I'd suggest making it a global variable, so you can access it within other subs and forms):

Public downloadManager As New DownloadHandler()
'The following would go in your "OnLoad" sub or similar:
MyBrowser.DownloadHandler = downloadManager()

Hope this helps! 1f609

Like +1 Dislike

Thanks man! Really helped

Like +1 Dislike