c# – 如何使CommonOpenFileDialog仅选择文件夹,但仍显示文件?

我正在使用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();

相关文章

在要实现单例模式的类当中添加如下代码:实例化的时候:frmC...
1、如果制作圆角窗体,窗体先继承DOTNETBAR的:public parti...
根据网上资料,自己很粗略的实现了一个winform搜索提示,但是...
近期在做DSOFramer这个控件,打算自己弄一个自定义控件来封装...
今天玩了一把WMI,查询了一下电脑的硬件信息,感觉很多代码都...
最近在研究WinWordControl这个控件,因为上级要求在系统里,...