Programmatically Open Word Document Located in the Computer in C#
Instead of adding interop in your reference, you may also consider to use this:
System.Diagnostics.Process.Start(@"C:\Test\NewDocument.docx");
first add the dll of Microsoft.Office.Interop.Word
to your references then add this:
using Microsoft.Office.Interop.Word;
and use the following code:
Application ap = new Application();
Document document = ap.Documents.Open(@"C:\Test\NewDocument.docx");
This Application
is not this.Application
it's Microsoft.Office.Interop.Word.Application
.
So you can use this code:
using System;
using Microsoft.Office.Interop.Word;
class Program
{
static void Main()
{
// Open a doc file.
Application application = new Application();
Document document = application.Documents.Open("C:\\word.doc");
//Do whatever you want
// Close word.
application.Quit();
}
}