Hello,
I've got an app in which user browses (openfiledialog) to a file, opens it, and the code retrieves the filename and path.
Drama occurs when further on in the app we go to open the file. In this case an app (call it myapp.exe "path\filename") started using System.Diagnostics.Process.Start(). The message is "unable to open file" or something to that effect (depends on what function is trying to open it after the the openfiledialog).
This works when the parameters (file paths) for myapp.exe are hardcoded in the Arguments method but not when when constructed using the openfiledialog(). What's the go with this? I had the same problem connecting to an interbase file (using openfiledialog) and researched for a month on what was going on but only came up with a work round using paths stored in an INI file.
Here is the code I'ver whittled down to basic form
string strPathData = null;
OpenFileDialog dlg = new OpenFileDialog();
if (dlg.ShoeDialog() == Dialog.Result.OK)
{
dlg.OpenFile();
strPathData = dlg.FileName;
}
dlg.Dispose();
char c = (char)34; // Rabit ears
System.Diagnostics.Process.StartInfo psi = new System.Diagnostics.Process.StartInfo();
psi.FileName = "myApp.exe"
psi.Arguments = c + strPathData + c; // Works with "c:\\mypath\\myfile.dat" here instead
psi.WorkingDirectory = "C:\\mypath";
System.Diagnostics.Process p = System.Diagnostics.Process.Start(psi);
I've checked the Argument string and it is congruent to the hardcoded string.
As I said it only fails when the OpenFileDialog is used. I just wish I could find some article on why it doesn't work. Is it some kind of lock? The file in question is a Clarion DAT file all by itself. No clarion application running (or installed!).
Thanks in advance for any pointers
Anthony
I've got an app in which user browses (openfiledialog) to a file, opens it, and the code retrieves the filename and path.
Drama occurs when further on in the app we go to open the file. In this case an app (call it myapp.exe "path\filename") started using System.Diagnostics.Process.Start(). The message is "unable to open file" or something to that effect (depends on what function is trying to open it after the the openfiledialog).
This works when the parameters (file paths) for myapp.exe are hardcoded in the Arguments method but not when when constructed using the openfiledialog(). What's the go with this? I had the same problem connecting to an interbase file (using openfiledialog) and researched for a month on what was going on but only came up with a work round using paths stored in an INI file.
Here is the code I'ver whittled down to basic form
string strPathData = null;
OpenFileDialog dlg = new OpenFileDialog();
if (dlg.ShoeDialog() == Dialog.Result.OK)
{
dlg.OpenFile();
strPathData = dlg.FileName;
}
dlg.Dispose();
char c = (char)34; // Rabit ears
System.Diagnostics.Process.StartInfo psi = new System.Diagnostics.Process.StartInfo();
psi.FileName = "myApp.exe"
psi.Arguments = c + strPathData + c; // Works with "c:\\mypath\\myfile.dat" here instead
psi.WorkingDirectory = "C:\\mypath";
System.Diagnostics.Process p = System.Diagnostics.Process.Start(psi);
I've checked the Argument string and it is congruent to the hardcoded string.
As I said it only fails when the OpenFileDialog is used. I just wish I could find some article on why it doesn't work. Is it some kind of lock? The file in question is a Clarion DAT file all by itself. No clarion application running (or installed!).
Thanks in advance for any pointers
Anthony