Using WebBrowser to open office documents inside a Windows Forms Form

W

W.John Guineau

Using Visual Studio.Net 2005 Team Edition for Software Developers on a
Windows XP machine.

Microsoft Support article 304662, dated 1/10/2006 shows how to use the
WebBrowser control to open word/excel documents inside a Form.

http://support.microsoft.com/?id=304662

The basic code works - I can put a WebBrowser control into a form and then
call webBrowser1.Navigate( url ) and if 'url' is a .doc or a .xls file,
word/excel open and display the document. Very cool!

However, the article goes on to say that you can then get ahold of the
automation object from within the "NavigateComplete2" event handler (see
steps 7 and 8 in the article).

However, the webBrowser1 object created by the designer does not appear to
have a 'NavigateComplete2' method (event) and I can find no help for the
'AxSHDocVw' class referenced in the parameter list for the NavigateComplete2
event handler code.

The fact that the article's code has a WebBrowser instance named
'axWebBrowser1' leads me to believe that I do not have the same WebBrowser
class used in the article. The article is dated 1/10/06, so it appears very
current and specifically mentions that it applies to .Net 2005.

Has anyone gotten this to work?

thanks!

john
 
L

Luke Zhang [MSFT]

Hi John,

This article mainly foucs on vs.net 2003, so that there will be some
difference in VS.NET 2005. In VS.NET 2005, you can add the webbrowser
control directly from toolbox. And there is no "NavigateComplete2" event,
you can use the event "Navigated" instead.

Hope this help,

Luke Zhang
Microsoft Online Community Support

==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================

(This posting is provided "AS IS", with no warranties, and confers no
rights.)
 
W

W.John Guineau

Thanks Luke.

I had tried that, but the "Navigated" event does not have the same arguments
as NavigateComplete2 in the article. It has a "WebBrowserNavigatedEventArgs"
which contains only a 'url' member.

I can get to the "Document" of the WebBrowser ('sender' in the event handler
arguments), it is null when a Word or Excel doc is loaded.

Perhaps you could give a .Net 2.0/VS.Net 2005 example equivilent to the
original article?

john
 
J

Jonathan Rothwell

John,

I remember reading an article in a technology journal about this - it did
mention something about fiddling with WebBrowser. I'll see if I can fish it
out. If this helps, it was the UK journal Personal Computer World, latest
edition.
 
L

Luke Zhang [MSFT]

Dear John,

I understand you want to use the WebBrowser control in .NET 2.0 VS 2005 to
handle the Word document.
But as far as I know, this .NET 2.0 Component actually provides a managed
wrapper for the WebBrowser ActiveX control, so up till now it cannot
provide all the original functions of the ActiveX control. The Document
property you mentioned is actually an HtmlDocument Class and if a Word
document is open it will return null.

But if you really want to get full control of the document opened, I
suggest you use the WebBrowser ActiveX control in VS 2005.
It is also very easy to use.
1. Right click on the ToolBox (usually on the left of IDE), and click
"Choose Item¡­" to open the "Choose ToolBox Item" dialog.
2. On the "COM Components" tab, check the box of "Microsoft Web Browser"
and then click OK to close the dialog.
3. Now you can see "Microsoft Web Browser" appears in your ToolBox.
After you have added this control, you can use it by drag and drop like
other .NET Components.

Hope this will help you.


Luke Zhang
Microsoft Online Community Support

==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================

(This posting is provided "AS IS", with no warranties, and confers no
rights.)
 
W

W.John Guineau

Hi Luke,

That was exactly what I was looking for, thanks!

Maybe you guys should update that article to let people know there are two
diffeent browser controls - the "original" ActiveX version and the managed
wrapper (which is the one in the designer toolbox by default).

john
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top