Force CEFSharp to download without showing dialog
Asked Answered
G

1

4

I have a WPF application with CEFSharp, it's a web browser, when I click on a download link it will show me a dialog and ask me where you want to save the file?
How can I force the web browser to download any files without showing dialog? I want to create some thing like google chrome. so when you click on a download link it will download the file to a default path (usually it's in "Documents/Downloads")

now how can I implement this in my application?
if I need to change CEFSharp source code please tell more details because I found some solution but there aren't a complete example, there was just a part of code! thank you.

Gateshead answered 17/2, 2015 at 15:45 Comment(0)
S
5

There is an example in the main CefSharp GitHub repository

This search points to the relevant code bits: https://github.com/cefsharp/CefSharp/search?q=DownloadHandler&type=Code&utf8=%E2%9C%93

You see the common example handler in the CefSharp.Example project gets instantiated from both the CefSharp.Example.WinForms and CefSharp.Example.Wpf projects. It's not that long since I tried playing around with the WinForms one, I'm less sure about the WPF one but with a quick glance it looks functional. If not it's a bug that needs fixing!

If you perform a search for IDownloadHandler you should see the documentation of the interface. It sounds like in your case you want to set the showDialog parameter to false.

Sheppard answered 17/2, 2015 at 22:27 Comment(2)
Despite the downloads directory being remembered when the dialog was showing, I found that setting showDialog to false defaulted the save path to where the app was running. So recommend setting the path too. Here is the complete line callback.Continue(Path.Combine(@"C:\Downloads\", downloadItem.SuggestedFileName), showDialog: false);Civility
is it possible to miss OpenFileDialog and write pre-coded path's as result of it?Joinder

© 2022 - 2024 — McMap. All rights reserved.