[英]Cef - upload file without shown OpenFileDialog
I need to have a way to select some file without display of OpenFileDialog. 我需要一种方法来选择某些文件而不显示OpenFileDialog。
Yes, I know that CEF is not the best way to automate sth, but I need to do this with CEF. 是的,我知道CEF并不是使sth自动化的最佳方法,但是我需要使用CEF做到这一点。
I have found that this is possible up from 2014: https://github.com/cefsharp/CefSharp/pull/342/commits/c11fe8e4e97179ff4073208c13f9ff29e61bab79 我发现这可能从2014年开始出现: https : //github.com/cefsharp/CefSharp/pull/342/commits/c11fe8e4e97179ff4073208c13f9ff29e61bab79
in this commit added ability to overriding file browse dialog result... But I still do not understand how to use this ability... 在这个提交中添加了覆盖文件浏览对话框结果的功能...但是我仍然不明白如何使用此功能...
And I have found sample of usage, but it doesn't work: 而且我发现了用法示例,但是不起作用:
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;
}
}
}
it'ts shows me error that at the moment IDialogHandler in OnFileDialog have another parameters (without result). 它不会向我显示错误,即目前OnFileDialog中的IDialogHandler具有另一个参数(无结果)。
Current parameters list is: 当前参数列表为:
public bool OnFileDialog(IWebBrowser browserControl, IBrowser browser, CefFileDialogMode mode, string title, string defaultFilePath, List<string> acceptFilters, int selectedAcceptFilter, IFileDialogCallback callback)
Can someone help me? 有人能帮我吗?
I'm using the latest CEFsharp: 63.0.3 我正在使用最新的CEFsharp:63.0.3
public class TempFileDialogHandler : IDialogHandler
{
string[] _filePath;
public TempFileDialogHandler(params string[] filePath)
{
_filePath = filePath;
}
public bool OnFileDialog(IWebBrowser browserControl, IBrowser browser, CefFileDialogMode mode, string title, string defaultFilePath, List<string> acceptFilters, int selectedAcceptFilter, IFileDialogCallback callback)
{
callback.Continue(0, _filePath.ToList());
return true;
}
}
And usage: 和用法:
Browser.DialogHandler = new TempFileDialogHandler(files);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.