|
-
Sep 21st, 2002, 05:46 AM
#1
Thread Starter
Addicted Member
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.
-
Sep 21st, 2002, 07:57 AM
#2
Frenzied Member
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
-
Sep 21st, 2002, 10:29 AM
#3
Thread Starter
Addicted Member
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.
-
Sep 21st, 2002, 11:52 AM
#4
PowerPoster
Maybe try something like this:
System.Diagnostics.Process proc = new System.Diagnostics.Process();
proc.EnableRaisingEvents=false;
proc.StartInfo.FileName = sFile;
proc.Start();
-
Sep 22nd, 2002, 10:24 AM
#5
Thread Starter
Addicted Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|