C# 文件夹浏览器对话框初始文件夹
我正在寻找并打开文件夹对话框(wpf)。我得到wpf的Ookii对话框,我使用VistaFolderBrowserDialog。(我不喜欢Windows窗体的FolderBrowser对话框) 我保存“上次打开的文件夹”。因此,下次用户打开此VistaFolderBrowser对话框时,初始文件夹就是我保存的“最后一个” VistaFolderBrowserDialog具有属性=>RootFolder: 公共环境::…SpecialFolder根文件夹{get;set;} 但它是一种特殊的文件夹类型 因此,我正在寻找一种将字符串OpenFolderPath设置为RootFolder属性的方法C# 文件夹浏览器对话框初始文件夹,c#,wpf,ookii,C#,Wpf,Ookii,我正在寻找并打开文件夹对话框(wpf)。我得到wpf的Ookii对话框,我使用VistaFolderBrowserDialog。(我不喜欢Windows窗体的FolderBrowser对话框) 我保存“上次打开的文件夹”。因此,下次用户打开此VistaFolderBrowser对话框时,初始文件夹就是我保存的“最后一个” VistaFolderBrowserDialog具有属性=>RootFolder: 公共环境::…SpecialFolder根文件夹{get;set;} 但它是一种特殊的文件夹
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;
但这必须在显示对话框之前完成
所以它应该看起来像
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
}
如果这能解决问题,请告诉我
我希望我是有用的。您需要特殊文件夹路径作为完整字符串吗?如果您确实尝试这个var folder=Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);非常感谢。反过来说。因为属性是SpecialFolder类型,所以我需要路径字符串作为SpecialFolder
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
}