In a visual basic (.NET) project I am using CefSharp (Nugget). How can I change the browser download folder? In the official CefSharp documentation the developers talk about the IDownloadHandler interface. This class is used to handle CefSharp file downloads. Based on what I investigated, I could try to instantiate IDownloadHandler like this:
public class DownloadHandler : IDownloadHandler
{
public event EventHandler<DownloadItem> OnBeforeDownloadFired;
public event EventHandler<DownloadItem> OnDownloadUpdatedFired;
public void OnBeforeDownload(IBrowser browser, DownloadItem downloadItem, IBeforeDownloadCallback callback)
{
var handler = OnBeforeDownloadFired;
if (handler != null)
{
handler(this, downloadItem);
}
if (!callback.IsDisposed)
{
using (callback)
{
callback.Continue(@"C:\Users\" +
System.Security.Principal.WindowsIdentity.GetCurrent().Name. +
@"\Downloads\" +
downloadItem.SuggestedFileName,
showDialog: false);
}
}
}
public void OnDownloadUpdated(IBrowser browser, DownloadItem downloadItem, IDownloadItemCallback callback)
{
var handler = OnDownloadUpdatedFired;
if (handler != null)
{
handler(this, downloadItem);
}
}
}
My question is, where should I apply this code, I am guessing not in my visual basic program, which makes me think the changes need to be done on the source code of CerfSharp? If so, how can I do it?
Thanks a lot everyone!