My application updates items on a database and then opens mail-merge documents which are populated with the fields from a table on the database.
I have the .docs saved to a network drive, but my two previous attempts to open them have returned different errors; either word tells me that there was an error trying to open the file, or it tells me that the file is in use by myself and is locked for editing.
Here are the two methods, respectively:
//method1
ProcessStartInfo startInfo = new ProcessStartInfo();
startInfo.FileName = "WINWORD.EXE";
startInfo.Arguments = fileName;
Process.Start(startInfo);
//method 2 (a simplified version of the first)
Process.Start(fileName);
Is there another way to open these Microsoft Word documents using C#, or anything clearly wrong with the methods above?
Both your methods should work... but here is another one to try. Maybe you will get a better error message.
var type = Type.GetTypeFromProgID("Word.Application");
dynamic word = Activator.CreateInstance(type);
word.Visible = true;
word.Documents.Open(@"C:\test.docx");