Suppressing the Save/Open Dialog box in a WebBrowser control

喜你入骨 提交于 2019-11-29 22:17:27

问题


I have a WebBrowser control that is automatically logging me into a website and attempting to download CSV data automatically. Everything is working fine, except, when it tries to download the CSV data, it is popping up a dialog box, asking if I want to save the file or open it (just like in IE). What I am trying to do is automatically download the CSV file to a file of my choosing (or better, save the CSV file directly into a string variable). I can't seem to figure out how to suppress the dialog box and capture the download automatically. I've search and found a few solutions, however, they don't work for me because:

1) I am now using a GUI. All this is done in a class (therefore, methods such as SendKeys would not be a viable solution)

2) The download comes from a secure site and requires authentication. The WebBrowser control handles all that for me, but if I use a WebRequest and WebResponse to try to capture the download, I am no longer authenticated.

I am using C#. Any help would be appreciated.


回答1:


You can hook up your own IDownloadManager implementation that does download quietly. For Windows Forms, this means you need to override the WebBrowser.CreateWebBrowserSiteBase method to provide your extended control site. Check Webbrowser Control Downloads for details.




回答2:


you can't suppress the file download dialog as that it would be a major security risk. I would suggest you investigate other routes to get your request authenticated if you want to make this process automatic.



来源:https://stackoverflow.com/questions/3538874/suppressing-the-save-open-dialog-box-in-a-webbrowser-control

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!