CefSharp(二) 文件下载功能

上节讲了如何将CefSharp集成到C#中,但集成后将web界面链接进ChromiumWebBrowser后,但web界面上下载附件的功能不好使咯。

百度了半天还是没搞定,只能去看官网的Excample和源代码,最后瞎猫碰死耗子给搞定了,需要去实现一个接口。


public RevenueContractFrmWeb(Adapter adapter)
        {
            Adapter = adapter;
            InitializeComponent();
            //string url = GlobalDefination.Urlex + "/go-logistics-client/inAndOutPages/incomeContract/contractMg/ContractMain.jsp"; 
            //webBrowser.Navigate(url+"?sessionId=" + adapter.SessionId);

            string url =  GlobalDefination.Urlex + "/go-logistics-client/inAndOutPages/incomeContract/contractMg/ContractMain.jsp?sessionId=" + adapter.SessionId;
            CefSharp.WinForms.ChromiumWebBrowser wb = new CefSharp.WinForms.ChromiumWebBrowser(url);
            wb.Dock = DockStyle.Fill;
            this.Controls.Add(wb); 
            wb.DownloadHandler = new DownloadHandler();
        }
 internal cl
 ass DownloadHandler : IDownloadHandler
        {

            public bool OnBeforeDownload(CefSharp.DownloadItem downloadItem, out string downloadPath, out bool showDialog)
            {
                downloadPath ="";
                showDialog = true;
                return true;
            }
            public bool OnDownloadUpdated(CefSharp.DownloadItem downloadItem)
            {
                return false;
            }
        }

public bool OnDownloadUpdated(CefSharp.DownloadItem downloadItem)这个地方要return false,就会弹出一个下载文件选择框,否则就不会弹出。
CefSharp(二) 文件下载功能_第1张图片

你可能感兴趣的:(CefSharp)