Cef - 上传文件而不显示 OpenFileDialog
Cef - upload file without shown OpenFileDialog
我需要一种方法来 select 某些文件而不显示 OpenFileDialog。
是的,我知道 CEF 不是自动化某物的最佳方式,但我需要使用 CEF 来实现。
我发现从 2014 年开始这是可能的:
https://github.com/cefsharp/CefSharp/pull/342/commits/c11fe8e4e97179ff4073208c13f9ff29e61bab79
在此提交中添加了覆盖文件浏览对话框结果的功能...但我仍然不明白如何使用此功能...
我找到了使用示例,但它不起作用:
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;
}
}
}
它没有向我显示错误,目前 OnFileDialog 中的 IDialogHandler 有另一个参数(没有结果)。
当前参数列表为:
public bool OnFileDialog(IWebBrowser browserControl, IBrowser browser, CefFileDialogMode mode, string title, string defaultFilePath, List<string> acceptFilters, int selectedAcceptFilter, IFileDialogCallback callback)
有人可以帮助我吗?
我使用的是最新的 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;
}
}
和用法:
Browser.DialogHandler = new TempFileDialogHandler(files);
我需要一种方法来 select 某些文件而不显示 OpenFileDialog。
是的,我知道 CEF 不是自动化某物的最佳方式,但我需要使用 CEF 来实现。
我发现从 2014 年开始这是可能的: https://github.com/cefsharp/CefSharp/pull/342/commits/c11fe8e4e97179ff4073208c13f9ff29e61bab79
在此提交中添加了覆盖文件浏览对话框结果的功能...但我仍然不明白如何使用此功能...
我找到了使用示例,但它不起作用:
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;
}
}
}
它没有向我显示错误,目前 OnFileDialog 中的 IDialogHandler 有另一个参数(没有结果)。
当前参数列表为:
public bool OnFileDialog(IWebBrowser browserControl, IBrowser browser, CefFileDialogMode mode, string title, string defaultFilePath, List<string> acceptFilters, int selectedAcceptFilter, IFileDialogCallback callback)
有人可以帮助我吗?
我使用的是最新的 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;
}
}
和用法:
Browser.DialogHandler = new TempFileDialogHandler(files);