禁止托管WebBrowser“另存为".对话 [英] Suppressing Hosted WebBrowser "Save As" dialog

查看:72
本文介绍了禁止托管WebBrowser“另存为".对话的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有许多商业用户,他们定期从供应商网站下载报告.我想使用VB.NET或C#表单为他们自动化此过程.

看来供应商已经竭尽全力使我感到困难.进入网站后,用户需要通过HTTPS表单输入其用户名和密码.该网站的其余部分是HTTPS.然后,他们需要浏览几个不同的页面,这些页面设置了报表请求所需的会话变量(cookie).最终,这些报告从HTTP POST请求返回,这些请求采用不同参数的存储桶.还有一个嵌入式JS,它会在表单发布之前设置其中的一些参数.

我玩过许多不同的选项,但最终选择使用WebBrowser控件浏览网站,就像我是普通用户一样.这使我可以忽略格式化最终POST请求所涉及的复杂逻辑,并且(从某种程度上)将来可以证明我的代码不受供应商可能对其网站所做的更改的影响.

到目前为止,一切都很好.

表单过帐后,将显示两个对话框.单击文件下载"(显示打开",保存"和取消"按钮),然后,如果单击保存",则出现另存为"对话框.使用BimJeam优秀文章(禁止托管WebBrowser控制对话框)的修改版本,我可以截取并单击文件下载"对话框上的保存".我的问题是,我不知道如何拦截另存为"对话框.它似乎不会触发WM_INITDIALOG消息,并且不会以任何期望的名称出现在消息队列中.

有没有人做过此事,或者知道解决此问题的好方法?

预先感谢.

I have a number business users who regularly download reports from a vendor website. I''d like to automate this process for them using a VB.NET or C# form.

It looks like the vendor has gone out of their way to make this difficult for me. Upon entering the website, the user needs to enter their username and password via a HTTPS form. The rest of the site is HTTPS. They then need to navigate thru a few different pages, which set up session variables (cookies) necessary for the report request. The reports are finally returned from HTTP POST requests which take a bucketload of different parameters. There is also embedded JS which sets up some of these parameters before the form is posted.

I''ve played with a number of different options, but have finally opted for using the WebBrowser control to navigate thru the site as if I were a normal user. This allows me to ignore the convoluted logic involved in formatting up the final POST request, and also (somewhat) future proofs my code from changes the vendor might make to their website.

So far, so good.

When the form is POSTed, two dialog boxes are displayed; a "File Download" (showing Open, Save and Cancel buttons) and then, if you click Save, a "Save As" dialog. Using an modified version of BimJeam''s excellent article (Suppressing Hosted WebBrowser Control Dialogs), I can intercept and click Save on the "File Download" dialog. My problem is, I can''t work out how to intercept the "Save As" dialog. It doesn''t seem to fire the WM_INITDIALOG message, and doesn''t appear in the message queue with any expected name.

Has anyone done this before, or know a good way to approach it?

Thanks in advance.

推荐答案

好吧,我将每50毫秒轮询一次
Ok, as a work around I''m polling
GetWindowHandle

,以查找标题为另存为"并与之交互的对话框.它出现时.这行得通,但是我确实看到对话框明显闪烁然后消失,这是不理想的.

希望会有更好的解决方案...

every 50ms for a dialog with the title "Save As" and interacting with it when it appears. This works, but I do get the dialog visibly flashing up and then disappearing, which is not ideal.

Hopefully a better solution will appear...


这篇关于禁止托管WebBrowser“另存为".对话的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆