我正在使用Microsoft的
CommonOpenFileDialog来允许用户选择一个文件夹,但是当对话框出现时,不会显示任何文件.当IsFolderPicker设置为true时,是否可以显示文件以及文件夹?
我当前的代码看起来像这样
var dialog = new CommonOpenFileDialog(); dialog.IsFolderPicker = true; if (dialog.ShowDialog() == CommonFileDialogResult.Ok) { SelectedFolderPath = dialog.FileName; }
解决方法
在我头顶,这是我做的
var dialog = new CommonOpenFileDialog { EnsurePathExists = true,EnsureFileExists = false,AllowNonFileSystemItems = false,DefaultFileName = "Select Folder",Title = "Select The Folder To Process" }; dialog.SetOpenButtonText("Select Folder"); if (dialog.ShowDialog() == CommonFileDialogResult.Ok) dirToProcess = Directory.Exists(dialog.FileName) ? dialog.FileName : Path.GetDirectoryName(dialog.FileName);
编辑:神圣2年前蝙蝠侠!
似乎几乎没有变化,下面的片段似乎做了这个工作
var openFolder = new CommonOpenFileDialog(); openFolder.AllowNonFileSystemItems = true; openFolder.Multiselect = true; openFolder.IsFolderPicker = true; openFolder.Title = "Select folders with jpg files"; if (openFolder.ShowDialog() != CommonFileDialogResult.Ok) { MessageBox.Show("No Folder selected"); return; } // get all the directories in selected dirctory var dirs = openFolder.FileNames.ToArray();