Set InitialDirectory for FolderBrowserDialog (转载)

it2024-11-21  1

The .NET FolderBrowserDialog class does not have an InitialDirectory property like the OpenFileDialog class.  But fortunately, it’s quite easy to set an initial folder in the FolderBrowserDialog:

FolderBrowserDialog dialog = new FolderBrowserDialog(); dialog.RootFolder = Environment.SpecialFolder.Desktop; dialog.SelectedPath = @"C:\Program Files"; if (dialog.ShowDialog() == DialogResult.OK) { Console.WriteLine( dialog.SelectedPath ); }

Note that you can choose other RootFolder’s like MyComputer and MyDocuments.  The SelectedPath must be a child of the RootFolder for this to work.

Given the sample code above, the dialog may look like this:

 

转载自:http://www.csharp411.com/set-initialdirectory-for-folderbrowserdialog/

转载于:https://www.cnblogs.com/wuhenke/archive/2010/04/18/1714568.html

相关资源:C# for 乱七八糟的看不懂
最新回复(0)