object o_null = System.Reflection.Missing.Value;
object o_true = ???
object
o_false = ???
object o_filePath = @"C:\my\filename.doc";
Word.Document
doc;
try
{
doc = wordApplication.Documents.Open(ref
o_filePath,
ref o_null, ref o_null, ref o_null, ref o_null,
ref o_null,
ref o_null, ref o_null, ref o_null, ref o_null,
ref o_null,
ref o_null, ref o_null, ref o_null, ref o_null,
ref o_null);
}
catch (Exception e)
{
MessageBox.Show("ERROR!
Couldn't open that file. "+ e.Message.ToString());
}
if you want to read text from the file, you can use
string alltext = doc.Content.Text
To save the document:
object o_filename = @"C:\a\nice\filename.doc";
object o_format =
Word.WdSaveFormat.wdFormatHTML;
object o_encoding = Microsoft.Office.Core.MsoEncoding.msoEncodingUTF8;
object
o_endings = Word.WdLineEndingType.wdCRLF;
try
{
wordApplication.ActiveDocument.SaveAs(ref o_filename, ref o_format, ref o_null,
ref o_null, ref o_null, ref o_null, ref o_null, ref o_null, ref o_null,
ref o_null, ref o_null, ref o_encoding, ref o_null,
ref o_null,
ref o_endings, ref o_null);
}
catch (Exception e)
{
MessageBox.Show("ERROR!
Couldn't save that file. "+ e.Message.ToString());
}
You must remember to quit the Word application and to discard the COM object afterwards:
doc.Close(ref o_null, ref o_null, ref o_null);
wordApplication.Quit(ref o_null,
ref o_null, ref o_null);
System.Runtime.InteropServices.Marshal.ReleaseComObject(wordApplication);
hope this help:
Cheers..