Click here to Skip to main content
15,881,852 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hey

I want to know how to build OpenFileLocation button.
I mean , after I select browse , ofd shows up. I select the .exe or whatever , then it prints to textbox1.text
C#
OpenFileDialog ofd = new OpenFileDialog();
            
            
            if (ofd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                this.textBox1.Text = ofd.FileName;
                
            }

and I created this
C#
Process.Start(textbox1.Text)

but , I want to create a button to open the folder which locates the exe i selected from the browse button.
Like , Open file location button
I tried this
C#
if (ofd.ShowDialog() == DialogResult.OK)
            {
                textBox1.Text = OpenFileDialog;
            }

But , it didnt worked.
Posted
Comments
Tamer Hatoum 28-Nov-12 16:00pm    
if you mean that you want to locate an .exe file then you want to start the chosen app. then you have to start the process by the file path not only the file name.

1 solution

Use the FolderBrowserDialog class


C#
if (ofd.ShowDialog() == DialogResult.OK)
{
   FolderBrowserDialog dialog = new FolderBrowserDialog();
   dialog.SelectedPath = Path.GetDirectoryName(ofd.FileName);
   dialog.ShowDialog();
   textBox1.Text = dialog.SelectedPath;
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900