C# 如何使用打开文件对话框选择文件夹
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9227917/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to use Open File Dialog to Select a Folder
提问by Demasterpl
Possible Duplicate:
How do you configure an OpenFileDIalog to select folders?
I'm using C# and I want to completely avoid SelectFolderDialog to select a folder. Instead, I want to use something closer to a OpenFileDialog just to select a folder.
我正在使用 C#,我想完全避免使用 SelectFolderDialog 来选择文件夹。相反,我想使用更接近 OpenFileDialog 的东西来选择一个文件夹。
For a more visual example, I'm looking for something close (if not exactly) like the following: http://i44.tinypic.com/x38tx1.png
对于更直观的示例,我正在寻找类似于以下内容的内容(如果不完全相同):http: //i44.tinypic.com/x38tx1.png


Any ideas?
有任何想法吗?
采纳答案by Heinzi
The folder selection dialog of Windows Vista looks quite similar to what you want. Unfortunately, .NET's FolderBrowserDialogshows the old Windows-XP-like dialog, which you want to avoid.
Windows Vista 的文件夹选择对话框看起来与您想要的非常相似。不幸的是,.NETFolderBrowserDialog显示了旧的类似 Windows-XP 的对话框,这是您想要避免的。
To access this Vista-style dialog, you can either
要访问这个 Vista 风格的对话框,您可以
- use some third-party .NET library (e.g. Ookii.Dialogs),
- use the relevant Windows API calls or
use the Windows API Code Pack:
using Microsoft.WindowsAPICodePack.Dialogs; ... var dialog = new CommonOpenFileDialog(); dialog.IsFolderPicker = true; CommonFileDialogResult result = dialog.ShowDialog();Note that this dialog is not available on operating systems older than Windows Vista, so be sure to check
CommonFileDialog.IsPlatformSupportedfirst.
- 使用一些第三方 .NET 库(例如Ookii.Dialogs),
- 使用相关的 Windows API 调用或
using Microsoft.WindowsAPICodePack.Dialogs; ... var dialog = new CommonOpenFileDialog(); dialog.IsFolderPicker = true; CommonFileDialogResult result = dialog.ShowDialog();请注意,此对话框在早于 Windows Vista 的操作系统上不可用,因此请务必先检查
CommonFileDialog.IsPlatformSupported。

