Click here to Skip to main content
11,811,971 members (67,535 online)
Rate this: bad
Please Sign up or sign in to vote.
See more: C#

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
OpenFileDialog ofd = new OpenFileDialog();
            if (ofd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                this.textBox1.Text = ofd.FileName;
and I created this
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
if (ofd.ShowDialog() == DialogResult.OK)
                textBox1.Text = OpenFileDialog;
But , it didnt worked.
Posted 28-Nov-12 9:52am
Tamer Hatoum at 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

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

Use the FolderBrowserDialog class

if (ofd.ShowDialog() == DialogResult.OK)
   FolderBrowserDialog dialog = new FolderBrowserDialog();
   dialog.SelectedPath = Path.GetDirectoryName(ofd.FileName);
   textBox1.Text = dialog.SelectedPath;

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

  Print Answers RSS
0 KrunalRohit 319
1 Abhinav S 215
2 Palash Mondal_ 210
3 CHill60 180
4 CPallini 135
0 OriginalGriff 3,893
1 KrunalRohit 2,441
2 CPallini 2,240
3 Maciej Los 2,155
4 ppolymorphe 1,725

Advertise | Privacy | Mobile
Web04 | 2.8.151002.1 | Last Updated 28 Nov 2012
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100