How to open word document and block a rest of the code until user exit word ?

  • Thread starter Thread starter Hamed_1983
  • Start date Start date
H

Hamed_1983

Guest
Hi

i've used this code to open the word document, then block the rest of code until the user close the word app :

ProcessStartInfo psi = new ProcessStartInfo(fullPath);
Process p = Process.Start(psi);

if (p == null)
{
// Word is already running, and handled the file above...
p = Process.GetProcessesByName("WINWORD")[0];
}

if (p == null)
{
// Handle error case...
// ie: Word may not be installed, or something else is handling this file...
}

p.WaitForExit(); // This line was blocked, until the user exit word app!
p.Close();

// load new order and save to datarow
byte[] changedDocument = Utilities.ReadDocument2ByteArray(fullPath);

The above code works for word 2007, but in 2013 (or maybe higher), this line does not block :

p.WaitForExit();

Can anybody help me how to solve this problem ?

thanks in advance.




Database Helper v 2.0.0

Continue reading...
 
Back
Top