【发布时间】:2014-05-26 09:11:14
【问题描述】:
您好,我正在尝试设置文件夹浏览器对话框的根文件夹。 FolderBrowserDialog 的 RootFolder 属性可以设置为 Environment.SpecialFolder 枚举的元素。
FolderBrowserDialog folderDlg = new FolderBrowserDialog();
folderDlg.RootFolder = Environment.SpecialFolder.MyDocuments;
if (folderDlg.ShowDialog() == DialogResult.OK) {
...
}
问题是我不想将根文件夹设置为默认值。我希望它取决于一些用户选择。
我已经阅读了有关在显示对话框之前设置 selectedPath 属性的信息。因此我尝试了这段代码
folderDlg.SelectedPath = pathSelectedByUser;
其中 pathSelectedByUser 是类似“C:\Temp\Backup”的字符串。差不多就是这样,但是只打开了Temp目录,选择了Backup目录,并没有打开Backup目录。
谁能帮忙?
【问题讨论】:
-
你希望如何让用户选择默认路径?
-
试试
pathSelectedByUser = "C:\Temp\Backup\" -
If the SelectedPath property is set before showing the dialog box, the folder with this path will be the selected folder, as long as SelectedPath is set to an absolute path that is a subfolder of RootFolder (or more accurately, points to a subfolder of the shell namespace represented by RootFolder).。Typically, after creating a new FolderBrowserDialog, you set the RootFolder to the location from which to start browsing. Optionally, you can set the SelectedPath to an absolute path of a subfolder of RootFolder that will initially be selected.