NinethSense oWnZ mE!: Praveen’s drawing book

Choose a Topic:

Fri
8
Feb '08

Word Automation with .NET

First refer COM objects - Microsoft Office xx.xx Object Libraryand Microsoft Word xx.xx Object Library

Here is the C# code for reading a word document:
 
Microsoft.Office.Interop.Word.Application oWord = new Microsoft.Office.Interop.Word.Application();
object ofilename = @“C:\testdoc.doc”;
object o = System.Reflection.Missing.Value;
object oreadonly = true;
object ovisible = false;
Microsoft.Office.Interop.Word.Document oDoc = oWord.Documents.Open(ref ofilename, ref o, ref oreadonly
    , ref o, ref o, ref o, ref o, ref o, ref o, ref o, ref o, ref ovisible, ref o, ref o, ref o, ref o);
 
textBox1.Text = oDoc.Content.Text; // contents available here
 
//Do not forget to quit other wize it will keep running in background
oDoc.Close(ref o, ref o, ref o);
oWord.Quit(ref o, ref o, ref o);
The CodeProject Microsoft Developer Network Official ASP.NET Forums Microsoft .NET Framework Community Microsoft Most Valuable Professional Kidoos forums Microsoft Visual Studio Developer Home Professional Information Technology Solutions Microsoft Research Home Kerala Microsoft Users Group Community Website