We have just encountered a strange bug with the open file dialog and the Process.Start command. The bug is as follows:

If you do a Process.Start(filename) before you Open up the OpenFileDialog everything is cool. However, once you open use the OpenFileDialog, you cannot then use the Process.Start(filename). The error that is thrown up is:
An Unhandled Exception of Type System.ComponentModel.Win32Exception occured in system.dll.
Additional Information: The system cannot find the file specified.

Eg:
Process.Start(@”c:\winnt\system32\notepad.exe”);
OpenFileDialog.ShowDialog()
Process.Start(@”c:\winnt\system32\notepad.exe”); //Error is thrown here

To fix the problem you will need to create a ProcessInfo component and set the UseShellExecute property to false.

From the documentation:
True to use the shell when starting the process; otherwise, the process is created directly from the executable file. The default is true.
When UseShellExecute is true, the WorkingDirectory property specifies the location of the executable. If WorkingDirectory is an empty string, the current directory is understood to contain the executable.
When UseShellExecute is false, the WorkingDirectory property is not used to find the executable. Instead, it is used by the process that is launched and only has meaning within the context of the new process.

Advertisements