如何拦截WebBrowser控件的“选择要上传的文件”窗口打开之前?
我的应用程序必须使用 webBrowser 控件自动填写表单并上传文件。 当我调用Member(“单击”)时,通常的“选择要上传的文件”表单会弹出,并出现在我可能同时使用的任何其他应用程序的前面。有没有办法拦截这个窗口,以便我可以将表单填写和文件上传放在后台?
My application has to automate form filling and upload files using a webBrowser control.
When I invokeMember("click"), the usual "Choose file to upload" form pops up and comes in front of any other application I may be using at the same time. Is there a way to intercept this window so that I can leep my form filling and file uploading in the background ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
答案是您可能可以,但这可能是一个极其复杂的过程。您可以挂接到 Windows CALLWNDPROCRET 通知链中,该链可以让您在 Web 浏览器控件处理事件之前获取事件(例如对话框创建)。我之前曾使用过它来执行诸如抑制“不受信任的证书”警告对话框之类的操作,但是我不建议您走这条路,除非您别无选择。
The answer is that you probably can, however it will likely be an absurdly complicated process. You can hook into the windows CALLWNDPROCRET notification chain which can allow you to get to events (like dialog creation) before they are processed by the webbrowser control. I've used this before to do things like suppress the 'untrusted certificate' warning dialog, however I wouldn't recommend going down this route unless you have absolutely no other choice.
出于安全原因,IE 不允许以编程方式设置要上传的文件。 (事实上,您甚至不能使用 SendKeys,因为 Microsoft 也堵住了这个漏洞。)
但是,您可以通过轻松地将文件添加到 HTTP 标头来完成您想要做的事情。有一个很棒的教程可以帮助您做到这一点:
http:// /www.codeproject.com/KB/aspnet/set-webbrowser-file-input.aspx
Due to security reasons, IE does not allow programmatically setting a file to upload. (In fact, you can't even use SendKeys, as Microsoft closed that hole too.)
However, you can accomplish what you are looking to do by adding the file to the HTTP header easily. There is a great tutorial that will help you do so:
http://www.codeproject.com/KB/aspnet/set-webbrowser-file-input.aspx