title: How to block downloads in .NET WebBrowser control?
body: <p>I need to prevent the .NET WebBrowser control from showing any "Do you want to open or save this file?" and "Save As" dialogs. Instead, I want to display a message box telling users that file downloads are disabled for security reasons.</p>
  
  <p>I started with the <code>FileDownload</code> event of <code>WebBrowser</code>, but it does not allow cancellation. Then, I used the approach from <a href="http://www.codeproject.com/KB/cpp/ExtendedWebBrowser.aspx?fid=285594&amp;select=2560552" rel="nofollow noreferrer">CodeProject: Extended .NET 2.0 WebBrowser Control</a> to implement my own event based on the original COM call using the interface <code>DWebBrowserEvents2</code>. When I fixed the code according to <a href="http://support.microsoft.com/?scid=kb%3Ben-us%3B325204&amp;x=15&amp;y=12" rel="nofollow noreferrer">an MS knowledge base entry about a bug with the FileDownload signature</a>, the event handler was called and I was able to cancel the download.</p>
  
  <p>This does not work with all downloads, though: download URLs pointing to an URL including <code>.exe</code> raise the event and can be cancelled before the dialog appears - but for others (like <code>.do</code>), the event handler is not called until the user clicks <code>Open</code>, <code>Save</code> or <code>Cancel</code> in the dialog.</p>
  
  <p>A possible solution might be to <a href="http://www.codeproject.com/KB/shell/WebBrowserControlDialogs.aspx" rel="nofollow noreferrer">intercept <code>WH_CALLWNDPROCRET</code> messages and 'answer' the dialog before it is shown to the user</a>, but it sounds like much effort and I also would prefer a cleaner solution...</p>
  
  <p>Does anybody know how to reliably block all downloads?</p>