Microsoft Word Technology Sample
This sample demonstrates using Microsoft Word from a managed application written in C#. Microsoft Word is the document component of Microsoft Office. Its object model is exposed through .NET Programmability Support. In the sample application, Microsoft Word is used as a COM server to demonstrate the interoperability of Microsoft Office with managed code.
Note |
---|
This sample requires Microsoft Office 2003 with .NET Programmability Support and Microsoft Office Primary Interop Assemblies. |
For information about using the samples, see the following topics:
To install .NET Programmability Support for Microsoft Office
Open the Control Panel and select Add or Remove Programs.
Select Microsoft Office 2003 or Microsoft Word 2003, and click Change. In the dialog, ensure the Add or Remove Features option button is selected, and click Next.
Select the Choose Advanced Customization of Applications checkbox, and click Next.
Expand the node for Word and click the downward-facing arrow adjacent to .NET Programmability Support. Select Run from My Computer.
Click Update.
To install the Microsoft Office Primary Interop Assemblies
- Install the Microsoft Office Primary Interop Assemblies (PIAs) from the Web.
A PIA contains type definitions for a native COM object. Once installed, specifying a type library when building an interop application is unnecessary.
To build the sample using the Command Prompt
Open a Command Prompt window and navigate to the \CS subdirectory under the Word directory.
Type msbuild WordAppCS.sln at the command line.
To build the sample using Visual Studio
Open Windows Explorer and navigate to the \CS directory under the Word directory.
Double-click the icon for WordAppCS.sln to open the file in Visual Studio.
In the Build menu, select Build Solution.
The application will be built in the default \Bin\Debug directory.
To run the sample
In the Command Prompt window, navigate to the directory that contains the built executable.
Type WordApp.exe at the command line.
Note This sample builds a console application. You must launch it using the command prompt in order to view its output. At the end of execution the sample will close the Internet Explorer window that it opened to show document methods and properties related to hyperlinks.
Requirements
Microsoft Office 2003
Primary Interop Assemblies for Microsoft Office
.NET Framework Version: 2.0, 1.1, 1.0
Remarks
The sample builds a console application written in C#. Review comments in the source code for more information about Office interoperability.
See Also
Reference
Missing
Process
Sleep
Start
System.Diagnostics
System.Reflection
System.Runtime.InteropServices
System.Threading
Other Resources
Design Considerations for Interoperation
Interoperating with Unmanaged Code
Managed and Unmanaged Events
Marshaling Data with COM Interop