如何使用“打开文件”对话框选择文件夹

可能重复:
如何配置OpenFileDIalog来选择文件夹?

我正在使用C#,我想完全避免使用SelectFolderDialog来选择文件夹。 相反,我想使用更接近OpenFileDialog的东西来选择一个文件夹。

有关更直观的示例,我正在寻找与以下内容非常接近的内容: http : //i44.tinypic.com/x38tx1.png

在此处输入图像描述

有任何想法吗?

Windows Vista的文件夹选择对话框看起来与您想要的非常相似。 不幸的是,.NET的FolderBrowserDialog显示了您想要避免的旧的类似Windows-XP的对话框。

要访问此Vista风格的对话框,您可以

  • 使用一些第三方.NET库(例如Ookii.Dialogs ),
  • 使用相关的Windows API调用或
  • 使用Windows API代码包 :

     using Microsoft.WindowsAPICodePack.Dialogs; ... var dialog = new CommonOpenFileDialog(); dialog.IsFolderPicker = true; CommonFileDialogResult result = dialog.ShowDialog(); 

    请注意,此对话框在Windows Vista之前的操作系统上不可用,因此请务必先检查CommonFileDialog.IsPlatformSupported