Michael Shepherd

Michael Shepherd

  • NA
  • 1
  • 29.2k

Override Webbrowser.FileDownload and Save Prompts

Sep 16 2013 3:05 PM
I'm developing a C# application to use the Visual Studio WebBrowser control and download documents from the
web.  (I'm using the Extended WebBrowser control supporting tabs – CSTabbedWebBrowser from
http://code.msdn.microsoft.com/windowsdesktop/Extended-WebBrowser-81b650d6).

At one point in the automation sequence, I need to click on a download link to download aseparate HTML document.  The underlying HTML link does not contain a URL to a specific document.  I believe the URL information and document are created dynamically.

When I click the link, an Open/Save/Cancel dialog popup appears.  Then, when I click the Save button, a separate windows API Save As dialog appears, requesting the file save name and location.

The popups have prevented me from automating the download process so I would like to override the download process. 

Can anyone help me with modifying the code for the WebBrowser control to bypass both of these dialogs and save the file to a location based upon a constant and a filename contained in a string variable? 

The CSTabbedWebBrowser already has some COM programming.  It attaches an event sink to the browser to override the new window event and create a new tab.  I assume that I need to use C++ and COM programming to override the FileDownload events but not sure how to accomplish this and complete the download.

The underlying HTML code under the download link does not specify a URL for the downloaded file, so I can't
use a c# download(URL) procedure.  I believe that the HTML in the downloaded file is generated dynamically.

I've been trying to solve this problem for a couple of weeks.  I have experience with C# but the COM/C++ it giving me a challenge.

Any assistance would be greatly appreciated.


Answers (1)