Reputation: 1864
I am using CefSharp[49] in my windows project The download handler is used to cancel the download according to specific condition.
Below is my handler, the problem I am facing is that the window opening is the 'Open File' window instead of 'Save as' window.
public void OnBeforeDownload(IBrowser browser, DownloadItem downloadItem, IBeforeDownloadCallback callback)
{
if (!callback.IsDisposed)
{
using (callback)
{
if (_allowDownload)
callback.Continue(downloadItem.SuggestedFileName, showDialog: true);
else
downloadItem.IsCancelled = !_allowDownload;
}
}
}
Upvotes: 1
Views: 3659
Reputation: 1864
i used the below code as a workaround
public void OnBeforeDownload(IBrowser browser, DownloadItem downloadItem, IBeforeDownloadCallback callback)
{
if (!callback.IsDisposed)
{
using (callback)
{
if (_allowDownload)
{
SaveFileDialog saveFileDialog = new SaveFileDialog();
saveFileDialog.FileName = downloadItem.SuggestedFileName;
saveFileDialog.Filter ="|*"+ System.IO.Path.GetExtension(saveFileDialog.FileName);
if (saveFileDialog.ShowDialog() == DialogResult.OK && saveFileDialog.FileName != "")
{
downloadItem.SuggestedFileName = saveFileDialog.FileName;
}
else
**downloadItem.IsCancelled = _allowDownload;**
}
else
**downloadItem.IsCancelled = !_allowDownload;**
callback.Continue(downloadItem.SuggestedFileName, showDialog: false);
}
}
}
public void OnDownloadUpdated(IBrowser browser, DownloadItem downloadItem, IDownloadItemCallback callback)
{
if (downloadItem.IsComplete || downloadItem.IsCancelled)
browser.CloseBrowser(true);
}
Upvotes: 1