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.

Tour Looking
  • 45
  • 1
  • 3

1 Answers1

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.

jornh
  • 1,369
  • 13
  • 27
  • 3
    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);` – Valamas Mar 20 '18 at 22:24
  • is it possible to miss OpenFileDialog and write pre-coded path's as result of it? – Andrew_STOP_RU_WAR_IN_UA Aug 05 '18 at 00:19