Process to open a document

  • Thread starter Thread starter Alan T
  • Start date Start date
A

Alan T

I have created a mail merged document at run time.
However, I cannot open the document everytime, sometime it did not get
opened, sometimes it can.
The document may be Word or text file.

public static void OpenDocument(string aFilename)

{

IntPtr result;

Process convertProcess = new Process();

try

{

convertProcess.StartInfo.Domain = "";

convertProcess.StartInfo.FileName = aFilename;

convertProcess.StartInfo.CreateNoWindow = true;

convertProcess.StartInfo.WindowStyle =
System.Diagnostics.ProcessWindowStyle.Maximized;

convertProcess.StartInfo.StandardErrorEncoding = null;

convertProcess.StartInfo.StandardOutputEncoding = null;

convertProcess.StartInfo.UseShellExecute = true;

convertProcess.StartInfo.LoadUserProfile = false;

convertProcess.StartInfo.Password = null;

convertProcess.StartInfo.UserName = "";

convertProcess.Start();

convertProcess.Dispose();

}

catch (Exception e)

{

try

{

convertProcess.Dispose();

}

catch

{

}

}


}
 
Text file? Text file sure cannot run macro. You are using VSTO or just VBA?

chanmm
 
Hi,

The method I stated was written by C#, the parameter aFilename is the full
path file name.
 
Did you check the process? Can it be the program is running but the Word is
not appearing?

chanmm
 
Why are you calling the Dispose() method immediately after Start()? Can
it be that the process is starting and then closing immediately?
-Samik
 
Back
Top