【发布时间】:2011-11-09 11:54:44
【问题描述】:
我需要用户选择一个目录,而不是一个文件。如何使用 Microsoft.Win32.OpenFileDialog(或任何其他组件)来做到这一点?
我在 VisualStudio 2010 (.net 4.0) 中使用 WPF4.0
【问题讨论】:
标签: .net wpf visual-studio-2010
我需要用户选择一个目录,而不是一个文件。如何使用 Microsoft.Win32.OpenFileDialog(或任何其他组件)来做到这一点?
我在 VisualStudio 2010 (.net 4.0) 中使用 WPF4.0
【问题讨论】:
标签: .net wpf visual-studio-2010
使用 System.Windows.Forms.FolderBrowserDialog :
var dlg = new System.Windows.Forms.FolderBrowserDialog();
dlg.ShowNewFolderButton = true; //if you want new folders as well
dlg.SelectedPath = someStartPath; //where to start
if( dlg.ShowDialog() == DialogResult.OK )
{
//ok user selected something
DoStuffWith( dlg.SelectedPath );
}
【讨论】:
您可以通过Windows API Code Pack 访问 Win32 生态系统中的许多其他标准对话框和控件。
【讨论】: