Link to home
Start Free TrialLog in
Avatar of muskok
muskok

asked on

How can I disable OPEN / SAVE / CANCEL dialog in WebBrowser class ?

I'm using the managed WebBrowser control that comes with .Net 2.0 to open office documents like Word and Excel. But before openning the document, it displays an annying warning and asks to the user whether he wants to open/save the document or cancel. I want to disable this message and open the document immediately because this is a document management application and it is safe to open all the documents. My application should not change any of the options in users registry and disabling this warning should be restricted to my browser control in the application. Other explorer windows should not be affected.

Thanks,
Mustafa Kok
Avatar of vo1d
vo1d
Flag of Germany image

you could find the windowhandle of that dialog by using the win32 api function findwindow and close that window by code, but that is not the best way to my opinion. do you get the same message, if you start such a document from office itself?
could you post a link with a screenshot of that message here?
Mustafa,

I've played around with the issue and it looks like it is a security setting in IE. You know that, though. Because of the nature of the managed control, I don't think you have access to this sort of functionality. The closest answer I could come up with was the CoInternetSetFeatureEnabled function in urlmon.dll. However, I couldn't get any combination of parameters to work.

Have you tried adding your site to the browser's trusted sites (via IE's Options)? That would eliminate most of your security concerns with other sites since they would have to have the same URL as your site to bypass this dialog like your site would.

Other than that, I'm unable to come up with anything.

Thanks.

Jason
another question, do you have to embed word or excel in ie or is it fine if you implement the office instance directly in your app?
Avatar of muskok
muskok

ASKER

Closing the window cannot be the solution because it is opened as dialog and the activex object waits for the user's response to the security question. It simply says that openning files from non trusted zones may be dangerous. It is a generic XP security warning window. I dont know how to add images but you can see the message if you open a blank iexplorer window then drag and drop an Excel file onto it.

Adding a new site to the trusted zones is possible through the IInternetSecurityManager interface, but it is not an option (I considered it before asking this question). Because our application should not touch any of the security settings on client computers, our clients are strict at this point.

I considered embedding word or other applications directly, but it so complex. You have to find the correct application for the given document type (from registry), create correct ActiveX object, add it to your form, pass file to it, close (dispose) it and be sure resources are relesed correctly, otherwise fatal COM exceptions and memory leaks occur. WebBrowser does this for us, but if you have example code that can do these things correctly it may also solve my problem.

This method is useful if you are familiar with OLE development using the unmanaged WebBrowser ActiveX control and you want to extend the functionality of the Windows Forms WebBrowser control, which is a managed wrapper for the ActiveX control. You can use this extensibility, for example, to customize the browser shortcut menu and shortcut keys or to provide a custom security configuration for hosted documents.

I searched MSDN for this issue and I found that it can be done by deriving a new WebBrowser class from the existing one and provide implementations for IDocHostUIHandler, IInternetSecurityManager... But there is no example how to do this. I wrote several different classes but they didn't work.

------- From MSDN -----
To use this feature, implement classes that inherit from the WebBrowser and WebBrowser.WebBrowserSite classes. The unmanaged WebBrowser ActiveX control uses the protected CreateWebBrowserSiteBase method to retrieve extensibility interfaces implemented by the WebBrowser.WebBrowserSite class. Override the CreateWebBrowserSiteBase method to return an instance of your own class that inherits from the WebBrowser.WebBrowserSite class. The WebBrowser.WebBrowserSite class provides default implementations of the OLE IDocHostUIHandler. You can provide your own implementation of this interface or implement any other WebBrowser ActiveX control interface in order to customize the behavior of the control.
-----------------------------

Thanks. Mustafa


that security warning comes with sp2, correct? how about disabling that check in the system? is that an option?

if you uncheck the checkbox of that security window once, the message will never come for that filetype, correct?
so you could find out the regkey for that info and set it up.

by posting my comment, you can close that window, i did not mean, close it by pressing cancle or the x of that window.
you can send that window the hotkey message for the open button, and that is possible.
you would just have to start another thread which checks all windows for the specific, send that message and stop the thread.
thats all.



Avatar of muskok

ASKER

Yes that security warning. Changing the registry key is possible but it affects the whole system (all of the iexplore windows) which is not acceptable. MSDN says it is possible to disable this warning for a specific instance of WebBrowser which I am trying to do.
why dont you modify that key during document loading and restore the old value after loading is finished?
Avatar of muskok

ASKER

Ony a few users has a right to change registry settings most of the users cannot do anything
ASKER CERTIFIED SOLUTION
Avatar of vo1d
vo1d
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
and one more comment, it depends of a setupped regkey, if word, excel, pp will start in your browser or not.
that key could be changed in explorer at the fileoptions. so you would not realy now, if your document will start in your browser or not.