我在窗體上有一個按鈕和一個文本框。當我點擊按鈕時,Microsoft Word就會啓動。當用戶關閉Word時,我想要獲取用戶保存其作品的文件名以顯示在文本框中。如何在用戶關閉Word時獲取文件名?
我使用下面的代碼button_click:
System.Diagnostics.ProcessStartInfo psi = new System.Diagnostics.ProcessStartInfo(@"C:\Program Files\Microsoft Office\Office12\winword.exe");
psi.RedirectStandardOutput = true;
psi.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
psi.UseShellExecute = false;
System.Diagnostics.Process listFiles;
listFiles = System.Diagnostics.Process.Start(psi);
System.IO.StreamReader myOutput = listFiles.StandardOutput;
listFiles.WaitForExit();
if (listFiles.HasExited)
{
System.IO.FileInfo ff = new System.IO.FileInfo(myOutput.ToString());
string output = myOutput.ReadToEnd();
this.processResults.Text = output;
}