Code Snip C#

I am sure somewhere there is the following code I would like to get:

File Path Box with Browse Button that opens the Windows file browser and when the file is selected
it puts it in the Path Field..  
AEIIAsked:
Who is Participating?
 
bruintjeCommented:
that would be pretty much the same with another dialog

        private void button1_Click(object sender, EventArgs e)
        {
            OpenFileDialog openFileDialog1 = new OpenFileDialog();
            // Show the openFileDialog.
            DialogResult result = openFileDialog1.ShowDialog();
            if (result == DialogResult.OK)
            {
                if(openFileDialog1.FileName !="")
                textBox1.Text  =  openFileDialog1.FileName ;
            }
       
        }
0
 
bruintjeCommented:
Hi AEII,

1. placed a folderbrowsedialog, a button and a textbox on a form
2. and used this code in the button click eventhandler

--------
            folderBrowserDialog1.ShowDialog();
            if(folderBrowserDialog1.SelectedPath!="")
            textBox1.Text  =  folderBrowserDialog1.SelectedPath;
--------

3. it will show the selected path in the textbox1 if one is selected

hope this helps a bit
bruintje
0
 
Fahad MukhtarDistinguished EngineerCommented:
a correction:
its FolderBrowserDialog class actually

FolderBrowserDialog folderBrowserDialog1 = new FolderBrowserDialog ();
// Show the FolderBrowserDialog.
DialogResult result = folderBrowserDialog1.ShowDialog();
if( result == DialogResult.OK )
        {
            MessageBox.Show(folderBrowserDialog1.SelectedPath);
        }
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

 
bruintjeCommented:
you can place the dialog on your form too, in 2005 at least
0
 
bruintjeCommented:
its a choice depending on your application, so no correction but an addition i tested before posting :)
0
 
Fahad MukhtarDistinguished EngineerCommented:
yes...
FolderBrowserDialog wasnt included in VS.Net 2002 (.net 1.0 FCL) (the code wont work for .net 1.0)
FolderBrowserDialog was included in VS.Net 2003 (.net 1.1 FCL) but wasnt included in the toolbox..(the code will work for .net 1.1)
 Finally in vs 2005 (.net 2.0) the control included in the toolbox (the code will work for .net 2.0)
0
 
bruintjeCommented:
:) you are correct i should've mentioned that in the comment
0
 
AEIIAuthor Commented:
Well we are getting close, but one more thing ...

The FolderBrowser only get to Folder Level ... I need to select
a specific .exe (file level)
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.