Search code examples
c#filedialog

User navigates to folder, I save that folder location to a string


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?


Solution

  •     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)