2

Looking for a solution to my issue. We are building a web browser control into a product for a client, they need to be able to detect when there is a File Upload box on a website, then instead of it launching the Windows 7 File Browser window, it needs to open their own custom designed one

Is there a browser event that allows us to capture that?

John Saunders
  • 160,644
  • 26
  • 247
  • 397
x06265616e
  • 854
  • 11
  • 14
  • Bypassing the dialog is a very attractive target for malware. You can fall back to the COM version of WebBrowser and get a DWebBrowserEvents2.FileDownload event. You however cannot find out what file is getting downloaded and you can only cancel it. – Hans Passant Oct 14 '12 at 12:24
  • Should the title of question be "Display Custom Dialog When File Uploaded" ? – aliassce Oct 14 '12 at 21:42

3 Answers3

5

You can hook up your own download manager that is effective only in your webbrowser control host process by implementing IServiceProvider in the control site and implement QueryService to return an IDownloadManager object when asked by the webbrowser control

In Windows Form's Webbrowser class, a control site is created for you by default, but you can override the control site by create your own WebBrowserSiteBase class and override the WebBrowser.CreateWebBrowserSiteBase Method. There is no such extensibility if you use the webbrowser control from WPF, Silverlight or Windows Phone.

I suggest you write the download manager in C++ due to the amount of interop required if you code in C#. There's an example for a C# webbrowser control using a native download manager here.

Sheng Jiang 蒋晟
  • 15,125
  • 2
  • 28
  • 46
0

You can catch the FileDownload event, and handle it yourself.

See http://msdn.microsoft.com/en-us/library/bb268220(v=vs.85).aspx

After showing your custom file dialog, send the data back to the webbrowser control, and submit the form.


Another option is to inject javascript into the control. Inject a code that replaces the call from the upload button, and show a form of your own instead.

Amirshk
  • 8,170
  • 2
  • 35
  • 64
0

So you want to modify the value of <input type=file .... You cannot do that with webbrowser control because it accesses DOM like javascript, vbscript vs. And if DOM allowed accessing and changing the uploaded file bad guys could easily steal your local files (using javascript) when you visit their pages.
Furthermore you can't even see the value of FileUpload because of that security issue.
If you want to select a file programmatically that is possible with a combination of SendKeys

aliassce
  • 1,197
  • 6
  • 19