File chooser dialog in Windows Foms programming. How to create?

I am writing a Windows Form desktop applicatiion. I need to allow for the application user to browse to
a file directory and to select a file to be uploaded. Now in the toolbox I see a control named
"FolderBrowserDialog". If I then drag and drop this control onto my windows form, I get an icon
at the bottom of the form labeled "folderBrowserDialog1".

Yet I do not get a button on the form that I can see which will allow the user to select the file
to be uploaded? Does this work differently in windows programming? Because I am expecting to see a button which the application user can press and then the file chooser dialog box displays.
LVL 2
brgdotnetcontractorAsked:
Who is Participating?
 
lazyberezovskyConnect With a Mentor Commented:
1) drag OpenFileDialog to your form
2) drag button to form
3) double click button
4) in button event handler add

private void button1_Click(object sender, EventArgs e)
{
    if (openFileDialog1.ShowDialog() == DialogResult.OK)
    {
        //Use openFileDialog1.FileName to get selected file name              
    }
}
0
 
CuteBugConnect With a Mentor Commented:
When you drag and drop the FolderBrowserDialog to your form you are just adding a component to your Form class. It will not show anything on Form. It will add a member to your Form class (like folderBrowserDialog1). You need to call its ShowDialog method to show it.

FolderBrowserDialog will let you choose a folder. In order to select a file you need to use OpenFileDialog.

http://dotnetperls.com/openfiledialog
http://www.java2s.com/Code/CSharp/GUI-Windows-Form/OpenFileDialogwithfiletypes.htm
http://dotnetdud.blogspot.com/2009/01/openfiledialog-in-c-how-to-use.html
0
All Courses

From novice to tech pro — start learning today.