文件夹浏览器对话框初始文件夹

Folder Browser Dialog Inital Folder

我正在寻找并打开文件夹对话框 (wpf)。我得到了 wpf 的 Ookii 对话框,我使用了 VistaFolderBrowserDialog。 (我不喜欢 Windows Forms 的 FolderBrowserDialog)。

我保存了"last open folder"。因此,下次用户打开此 VistaFolderBrowserDialog 时,初始文件夹是我保存的 "last one"。

...
//Save the new actual folder
MyProject.ProgramConfigurationFile.Instance.OpenFolderPath = System.IO.Path.GetDirectoryName(folderDialog.SelectedPath);

VistaFolderBrowserDialog 有 属性 => RootFolder:

public 环境..::..SpecialFolder RootFolder { get;放; } 但它是一个SpecialFolder类型。

所以我正在寻找一种方法来将我的 String OpenFolderPath 设置为 RootFolder 属性。

VistaFolderBrowserDialog folderDialog = new VistaFolderBrowserDialog();
folderDialog.Description = "Please select the folder";
folderDialog.UseDescriptionForTitle = true;
if ((bool)folderDialog.ShowDialog(this))
{
     //Get the last open folder saved (if exist).
     if(!String.IsNullOrEmpty(MyProject.ProgramConfigurationFile.Instance.OpenFolderPath))
     {
         folderDialog.RootFolder = Environment.SpecialFolder. //I would like to set OpenFolderPath
     }  
}

也欢迎使用其他文件夹浏览器。

非常感谢。

我以前不知道 Ookii 对话框,但经过一些搜索并了解打开文件夹对话框的常见工作原理后,我建议您将 lastOpenFolder 设置为 SelectedPath 属性

folderDialog.SelectedPath = MyProject.ProgramConfigurationFile.Instance.OpenFolderPath;

但这必须在 folderDialog.ShowDialog(this) 显示对话框之前完成。

所以它应该看起来像

VistaFolderBrowserDialog folderDialog = new VistaFolderBrowserDialog();
folderDialog.Description = "Please select the folder";
folderDialog.UseDescriptionForTitle = true;

if(!string.IsNullOrEmpty(MyProject.ProgramConfigurationFile.Instance.OpenFolderPath))
    folderDialog.SelectedPath = myProject.ProgramConfigurationFile.Instance.OpenFolderPath;

if ((bool)folderDialog.ShowDialog(this))
{
    string newSelectedFolderPath = folderDialog.SelectedPath;
    // Use new folderPath
}

如果这解决了问题,请告诉我。

希望我有用。