2

I want to load word document in different instance using Process.Start() method.

This is my code.

ProcessStartInfo info = new ProcessStartInfo();
info.FileName = @"D:\MyWordFile.doc";
info.Arguments = "/n"; //I have tried like this but it doesn't work
Process p = new Process();
p.StartInfo = info;
p.Start();

ok, I am trying to hold the process until document don't get exited using p.WaitForExit() method. It works fine when there is no word application is loaded. if the Word is already loaded in the Task Manager then it throws an error No process is associated with this object. I think it is because it is just loading document in existing process. So, I think I can resolve this issue by loading my word document in new Word Instance.

I have also read the support document and found some parameters that allows me to load word file in new instance. I have tried /n in the ProcessStartInfo.Argument property but, it doesn't work. I think i am doing mistake in assigning arguments in the process or assigned invalid argument. I don't know what is the issue here. Any help will be appreciated

Thanks & Regard.

Shell
  • 6,818
  • 11
  • 39
  • 70

1 Answers1

2

Arguments parameter is only used when FileName is an executable program. When FileName parameter is a document file, the command line from the file type association is used (from the Registry) and Arguments parameter is ignored.

You need to construct the whole command line:

Process.Start("winword", @"/n ""D:\MyWordFile.doc""");
Athari
  • 33,702
  • 16
  • 105
  • 146
  • Thanks for your answer, It is working without double quotation when the file name is not containing space ie. `mydoc.doc` but, if the file name is like `my doc.doc` then it takes the each word as a file name. I have also tried with double quotation like `"my word.doc"` but, it loads the document in the same instance even i try to call it from Windows's `Run` command. I am using MS Word 2007. you bring me just closed to it. the `/n` argument wont work with double quotation. – Shell Sep 22 '14 at 04:17