最近一直在做CEFsharp 方面的,遇到了下载文件的无法保存的问题 。 记录解决下。 主要是应用了
IDownloadHandler
调用方法:
web.MenuHandler = new MyWebContextMenu();
web.DownloadHandler = new MyDownLoadFile();
/// <summary>
/// 下载文件
/// </summary>
public class MyDownLoadFile : IDownloadHandler
{
public void OnBeforeDownload(IBrowser browser, DownloadItem downloadItem, IBeforeDownloadCallback callback)
{
if (!callback.IsDisposed)
{
using (callback)
{
callback.Continue(@"C:Users" +
System.Security.Principal.WindowsIdentity.GetCurrent().Name+
@"Downloads" +
downloadItem.SuggestedFileName,
showDialog: true);
}
}
}
public void OnDownloadUpdated(IBrowser browser, DownloadItem downloadItem, IDownloadItemCallback callback)
{
//downloadItem.IsCancelled = false;
}
public bool OnDownloadUpdated(CefSharp.DownloadItem downloadItem)
{
return false;
}
}