using System.Windows.Forms; FolderBrowserDialog dialog = new FolderBrowserDialog(); dialog.Description = "Select a folder."; dialog.ShowNewFolderButton = false; DialogResult result = dialog.ShowDialog(); if (result == DialogResult.OK) { string folderPath = dialog.SelectedPath; // Do something with the selected folder path. }
using System.IO; using System.Windows.Forms; FolderBrowserDialog dialog = new FolderBrowserDialog(); dialog.RootFolder = Environment.SpecialFolder.MyComputer; DialogResult result = dialog.ShowDialog(); if (result == DialogResult.OK) { string[] files = Directory.GetFiles(dialog.SelectedPath); // Do something with the files in the selected folder. }In this example, a FolderBrowserDialog is created with the root folder set to My Computer. The dialog is opened and if the user selects a folder and clicks OK, the files in the selected folder are retrieved using the Directory.GetFiles method and can be processed further. Both examples use the System.Windows.Forms library which is part of the .NET Framework.