Article ID: 304662 - Last Review: September 14, 2007 - Revision: 9.1 How to use the WebBrowser control to open Office documents in Visual C# 2005 or in Visual C# .NETThis article was previously published under Q304662
For a Microsoft Visual Basic .NET version of this article, see 304643
(http://support.microsoft.com/kb/304643/
)
.
On This PageSUMMARY
You may want to display or to embed a Microsoft Office document directly on a Microsoft Visual C# form. Microsoft Visual C# 2005 and Microsoft Visual C# .NET do not provide an OLE control that allows you to embed an Office document on a form. If you want to embed an existing document and open it as an in-place ActiveX document object in a Visual C# form, a potential solution for you is to use the Microsoft WebBrowser control. This article demonstrates how to browse to an existing Office document and how to display it inside a Visual C# form by using the WebBrowser control. MORE INFORMATION
ActiveX documents are embeddable OLE objects that behave more like ActiveX controls than traditional OLE objects. Unlike a traditional embedded object, an ActiveX document is not designed to be a contained object in a larger document. Instead, it is considered in itself a complete document that is merely being viewed (such as with Microsoft Internet Explorer) or being collected into a single resource with other documents (such as a Microsoft Office Binder file). An ActiveX document that is hosted in the WebBrowser control is always active; therefore, unlike traditional OLE embedded objects, there is no sense of in-place activation. Although Visual C# 2005 and Visual C# .NET do not currently support hosting ActiveX documents directly, you can use the WebBrowser control for this purpose. The WebBrowser control (Shdocvw.dll) is a part of Internet Explorer and can only be used on systems that have Internet Explorer installed. Creating a Visual C# application that opens Office documentsTo create a Visual C# application that opens Office documents, follow these steps:
What to consider when you use the WebBrowser controlYou should consider the following when you use the WebBrowser control:
What to consider when you use the WebBrowser control together with a 2007 Microsoft Office programBy default, the 2007 Office programs do not open Office documents in the Web browser. This behavior also affects the WebBrowser control. We recommended that you use a custom ActiveX document container instead of the WebBrowser control when you develop applications that open 2007 Office documents. For more information about custom ActiveX document containers, click the following article number to view the article in the Microsoft Knowledge Base:311765
(http://support.microsoft.com/kb/311765/
)
Visual C++ ActiveX control for hosting Office documents in Visual Basic or HTML
For existing applications that require backward compatibility with the WebBrowser control, you can modify the registry to configure Internet Explorer. You can use this method to configure Internet Explorer to open 2007 Office documents in the Web browser.
For more information, click the following article number to view the article in the Microsoft Knowledge Base:
927009
(http://support.microsoft.com/kb/927009/
)
A new window opens when you try to view a 2007 Microsoft Office program document in Windows Internet Explorer 7
Note If you modify the registry by using the method that is mentioned in Microsoft Knowledge Base article 927009, the changes affect the WebBrowser control that you use in the application. The changes also affect all instances of Internet Explorer. Additionally, this method may not work for any future versions of the Microsoft Office suites. Therefore, we recommend that you use this method only for compatibility with an existing application.REFERENCES
For more information about using the WebBrowser control, click the following article numbers to view the articles in the Microsoft Knowledge Base:
304562
(http://support.microsoft.com/kb/304562/
)
Visual Studio 2005 and Visual Studio .NET do not provide an OLE container control for Windows Forms
243058
(http://support.microsoft.com/kb/243058/
)
How to use the WebBrowser control to open an Office document
162719
(http://support.microsoft.com/kb/162719/
)
How to use the WebBrowser control from Visual Basic 5.0
202476
(http://support.microsoft.com/kb/202476/
)
BUG: Cannot edit Word document in OLE or WebBrowser control
188271
(http://support.microsoft.com/kb/188271/
)
How to print contents of the Web Browser control from VB
191692
(http://support.microsoft.com/kb/191692/
)
Shdocvw.dll is not included in PDW setup package
238313
(http://support.microsoft.com/kb/238313/
)
Accessing the Internet Explorer Document Object Model from Visual Basic
927009
(http://support.microsoft.com/kb/927009/
)
A new window opens when you try to view a 2007 Microsoft Office program document in Windows Internet Explorer 7
APPLIES TO
| Article Translations
|

Back to the top
