C.C.
C.C.

Reputation: 1070

can .net WebBrowser control avoid popup SaveFileDialog instead of saving this file silently?

lately I got a problem on using .net WebBrowser control. when redirect to a file downloading, the WebBrowser control popup the SaveFileDialog, I don't know if there is a way avoid this to let me choose a filename and save it to some location.

Thanks for any helps.

Upvotes: 2

Views: 3037

Answers (2)

Sheng Jiang 蒋晟
Sheng Jiang 蒋晟

Reputation: 15271

You can install your own custom download manager by adding IServiceProvider to your WebBrowserSiteBase-derived class, which needs to be constructed in your webbrowser-derived class as the return value of the WebBrowser.CreateWebBrowserSiteBase virtual function.

In your download manager implementation you can write the file saving code. See https://code.msdn.microsoft.com/windowsdesktop/CSIEDownloadManager-8ab5d910 for an example to grab the download url. If the download url requires login, you need to grab session cookies. Check http://vbmhwb.sourceforge.net/ for an example.

Upvotes: 1

Jon Skeet
Jon Skeet

Reputation: 1500665

You could handle the Navigating event, detect that it's a file download, make the request yourself with HttpWebRequest or WebClient, and cancel the navigating event within the handler.

Upvotes: 4

Related Questions