Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Suppressing the Save/Open Dialog box in a WebBrowser control

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.

like image 279
Icemanind Avatar asked Aug 21 '10 20:08

Icemanind


1 Answers

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.

like image 59
Sheng Jiang 蒋晟 Avatar answered Sep 22 '22 06:09

Sheng Jiang 蒋晟