So there is:

  1. CefSharp.Winforms
  2. Some site where there is a button Upload File, which opens OpenFileDialog

You open the site and click on the upload (manually). OpenFileDialog should NOT OPEN, but simply accept as a default address the file path.

This functionality was available in 2014: https://github.com/cefsharp/CefSharp/pull/342/commits/c11fe8e4e97179ff4073208c13f9ff29e61bab79

Then it was realized in the following way:

using System.Collections.Generic; using System.IO; namespace CefSharp.Example { public class TempFileDialogHandler : IDialogHandler { public bool OnFileDialog(IWebBrowser browser, string title, string defaultFileName, List<string> acceptTypes, out List<string> result) { result = new List<string> { Path.GetRandomFileName() }; return true; } } } 

after which the case should have been assigned to the browser instance:

 Browser.DialogHandler = new TempFileDialogHandler(files); 

Now the list of parameters has changed and looks like this:

 public bool OnFileDialog(IWebBrowser browserControl, IBrowser browser, CefFileDialogMode mode, string title, string defaultFilePath, List<string> acceptFilters, int selectedAcceptFilter, IFileDialogCallback callback) 

That is, the ability to set a Result of our OpenFileDialog has been removed. I still need to implement it ...

So the question is: how to get around this and implement this opportunity now?

Preferably without using WinApi.

Example of a page with a button: https://www.w3schools.com/tags/tryit.asp?filename=tryhtml_input_accept

  • It seems to me that this is due to security policy, and was removed specially, so it’s likely that I’ll not be able to delete the dialogue, my opinion. But you can slazit in the source code of Ceph, and cut off forever dialogue there. - NewView pm

1 answer 1

Now it is done like this:

 public class TempFileDialogHandler : IDialogHandler { public bool OnFileDialog(IWebBrowser browserControl, IBrowser browser, CefFileDialogMode mode, string title, string defaultFilePath, List<string> acceptFilters, int selectedAcceptFilter, IFileDialogCallback callback) { var files = new List<string> { "C:\\tmp\\1111.bmp" }; callback.Continue(0, files); return true; } } 
  • Thank you very much! As promised, I will put a reward for the question tomorrow and mark this answer as a winner. - Andrew