Results 1 to 5 of 5

Thread: Selecting a file with openFileDialog1?

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Aug 2002
    Location
    Coventry, England
    Posts
    169

    Selecting a file with openFileDialog1?

    Hello all, I'm new to C# so bear with me

    My little project is a Windows Application. It's a 'front-end' to run the console program mame.exe (Arcade emulation executable). I have a form with a openFileDialog1, browse button, run button and a textbox to show the name of the selected file. The user clicks browse to select a file, then the name of the file is shown in the textbox. When you click run, the program will run mame.exe along with the selected filename as an argument, e.g. 'mame.exe pacman'.

    What I have so far: I have openFileDialog1.ShowDialog(); on the btnBrowse_Click event. That shows the open dialog.

    What I need: I need to actually select the file and put the name of the file into txtFileName so the user can see what they have selected. Then finally I need to be able to run mame.exe with the selected filename as a argument when the user clicks btnRun.

    Any help will be much appreciated.

    Thanks.

    Darren.

  2. #2
    Frenzied Member DevGrp's Avatar
    Join Date
    Nov 2001
    Location
    Charlotte, NC
    Posts
    1,256
    This should do the trick

    Code:
    void btnBrowse_Click(object sender, EventArgs e)
    {
    	if(openFileDialog1.ShowDialog() == DialogResult.Ok)
    	{
    		txtFileName.Text = openFileDialog1.File;
    	}
    }
    
    void BtnRun_Click(object sender, EventArgs e)
    {
    	Sytem.Diagnostics.Process.Start("mame.exe" + " " + txtFileName.Text);
    }
    Hope that helped
    Dont gain the world and lose your soul

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Aug 2002
    Location
    Coventry, England
    Posts
    169
    Thanks for the info.

    Although I can only get it to work if I don't specify a parameter, e.g. it will only work if I have the following:

    System.Diagnostics.Process.Start("mame.exe");

    If I have:

    System.Diagnostics.Process.Start("mame.exe" + " " + txtFileName.Text);

    Or

    System.Diagnostics.Process.Start("mame.exe" + " " + openFileDialog1.FileName);

    It doesn't work. It comes up with the error: "Cannot find the specified file". I have the both EXEs and the parameter files all in the same folder, so it should see them ok.

    Hmmm.

    Again, thanks for your time/help.

  4. #4
    PowerPoster hellswraith's Avatar
    Join Date
    Jul 2002
    Location
    Washington St.
    Posts
    2,464
    Maybe try something like this:

    System.Diagnostics.Process proc = new System.Diagnostics.Process();
    proc.EnableRaisingEvents=false;
    proc.StartInfo.FileName = sFile;
    proc.Start();

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    Aug 2002
    Location
    Coventry, England
    Posts
    169
    I seem to have got that working now, thanks guys.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width