tags:

views:

48

answers:

3

How can I do this?

I want a user to click a button and then a small window pops up and lets me end-user navigate to X folder. Then I need to save the location of the folder to a string variable.

Any help, wise sages of StackOverflow?

A: 

If you're using Winforms, you can use a FolderBrowserDialog control. The path the user selects will be in the SelectedPath property.

JP Alioto
A: 
    using (FolderBrowserDialog dlg = new FolderBrowserDialog())
    {
        if (dlg.ShowDialog(this) == DialogResult.OK)
        {
            string s = dlg.SelectedPath;
        }
    }

(remove this if you aren't already in a winform)

Marc Gravell
It truly is ridiculous how quickly people help on this website. Thank you very much for the help. Works beautifully.
Sergio Tapia
A: 
string path = null;
FolderBrowserDialog dlg = new ();
if (dlg.ShowDialog() == DialogResult.OK)
{
    path = dlg.SelectedPath;
}
Thomas Levesque