Selecting file from folder using the FolderBrowserDialog

+1 Paul Hacker · August 14, 2015
I followed the videos on using the FolderBrowserDialog but I cannot select a file (they don't show up.)

I used the:
            FolderBrowserDialog fdb = new FolderBrowserDialog();
            if (fdb.ShowDialog() == System.Windows.Forms.DialogResult.OK)               // if good map of folders
            { 
                string[] files = Directory.GetDirectories(fdb.SelectedPath);                  // ok make a dimension string of path
                MessageBox.Show(Directory.GetParent(fdb.SelectedPath).ToString());
                foreach (string s in files)
                { MessageBox.Show(s); }
            }

But no matter where I click I get just the folder but no files underneath.

The video showed it working.. What am I doing wrong?

Thanks.

Post a Reply

Replies

Oldest  Newest  Rating
0 jethro daniel · August 16, 2015
try this



folderBrowserDialog fdb = new
FolderBrowserDialog();
if (fdb.ShowDialog() ==
System.Windows.Forms.
DialogResult.OK) // if good map of
folders
{
string[] files =
Directory.GetFiles
(fdb.SelectedPath); // ok make a
dimension string of path
MessageBox.Show
(Directory.GetParent
(fdb.SelectedPath).ToString());
foreach (string s in files)
{ MessageBox.Show(s); }
}
  • 1

C#

106,990 followers
About

C# is an object-oriented language designed for improving the development of web applications.

Links
Moderators