Display Custom Dialog When File Downloaded

一世执手 提交于 2019-12-04 15:29:19

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.

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.

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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!