none
Problem to execute an external file : The system cannot find the file specified

    Question

  • Hi
    i have a first exe file which takes 4 parameters an startup (the fourth parameter in path to file)
    in my main app i call my first exe file and pass some parameters like this :

    System.Diagnostics.ProcessStartInfo psi = new System.Diagnostics.ProcessStartInfo("DbInitWizard.exe");
    psi.Arguments = string.Format("{0} \"{1}\" {2} \"{3}\"",
    this.txtEnglishTitle.Text,
    this.txtPersianTitle.Text,
    this.txtCatalog.Text,
    this.txtScriptPath.Text);
    System.Diagnostics.Process.Start(psi);

    but when i click on a Browse button to locate a sample file, i got this error in last line of above code :

    The system cannot find the file specified.

    while it's correct path, i think it has problem with OpenFileDialog when i set my txtScriptPath.Text to OpenFileDialog.FileName as follow :

    private void btnOpenFile_Click(object sender, EventArgs e)
            {
                if (this.openFileDialog1.ShowDialog() == DialogResult.OK)
                {
                    this.txtScriptPath.Text = this.openFileDialog1.FileName;
                }
            }

    even, when i set path of the file in my code, it works ok, but when i open it via OpenFileDialog, i got this error.
    where is my problem and how to solve it ?
    thanks in advance.
    http://www.codeproject.com/KB/codegen/DatabaseHelper.aspx
    Sunday, February 28, 2010 12:06 PM

Answers

  • Your current directory is changed by the OpenFileDialog.
    To prevent this, set its RestoreDirectory property to true.
    • Marked as answer by Hamed_1983 Monday, March 01, 2010 3:20 PM
    Sunday, February 28, 2010 11:13 PM

All replies

  • Hi
    Please see the following code and it worked for me. Please  let me know if it doesn't solve your problem



     

    if (this.openFileDialog1.ShowDialog() == DialogResult.OK)

    {

     


    System.Diagnostics.ProcessStartInfo psi = new System.Diagnostics.ProcessStartInfo(this.openFileDialog1.FileName);
                System.Diagnostics.Process.Start(psi);

    }

     


    Please mark the post as answered if my post is the answer for your question, and mark other helpful posts as helpful. Thanks Vijay
    Sunday, February 28, 2010 1:07 PM
  • Hi
    Please see the following code and it worked for me. Please  let me know if it doesn't solve your problem



     

    if (this.openFileDialog1.ShowDialog() == DialogResult.OK)

     


    System.Diagnostics.ProcessStartInfo psi = new System.Diagnostics.ProcessStartInfo(this.openFileDialog1.FileName);
                System.Diagnostics.Process.Start(psi);

    }

     


    Please mark the post as answered if my post is the answer for your question, and mark other helpful posts as helpful. Thanks Vijay

     

    {

     


    Hi
    Thanks for reply, but i use openFileDialog as arguemnt, not for path to exe file, the openFileArgument returns a path of the file which pass to my exe as argument. plz check it with string.Format method to pass argument to your exe file and use openFileDialog to pass path of a sample file to your exe as argument and let me know the result.
    thanks in advance
    http://www.codeproject.com/KB/codegen/DatabaseHelper.aspx
    Sunday, February 28, 2010 8:48 PM
  • Your current directory is changed by the OpenFileDialog.
    To prevent this, set its RestoreDirectory property to true.
    • Marked as answer by Hamed_1983 Monday, March 01, 2010 3:20 PM
    Sunday, February 28, 2010 11:13 PM