.net 在WPF中使用OpenFileDialog时没有文件的文件夹路径?
如果文件夹中没有文件,如何使用WPF中的OpenFileDialog类获取文件夹路径.net 在WPF中使用OpenFileDialog时没有文件的文件夹路径?,.net,wpf,c#-4.0,wpf-controls,wpf-4.0,.net,Wpf,C# 4.0,Wpf Controls,Wpf 4.0,如果文件夹中没有文件,如何使用WPF中的OpenFileDialog类获取文件夹路径 { Microsoft.Win32.OpenFileDialog dlgObjDest = new Microsoft.Win32.OpenFileDialog(); dlgObjDest.Multiselect = true; dlgObjDest.DefaultExt = ".*"; dlgObjDest.InitialDirectory = "c:";
{
Microsoft.Win32.OpenFileDialog dlgObjDest = new Microsoft.Win32.OpenFileDialog();
dlgObjDest.Multiselect = true;
dlgObjDest.DefaultExt = ".*";
dlgObjDest.InitialDirectory = "c:";
if (dlgObjDest.ShowDialog() == true)
{
txtDestTesting.Text = System.IO.Path.GetDirectoryName(dlgObjDest.FileName);
}
}
但是当没有可选择的文件时,它无法获取文件夹路径如果没有选择任何文件,
ShowDialog()
将无法返回true
如果先将OpenFileDialog
的CheckFileExists
属性设置为true
,则用户可以输入不存在的文件名,然后您将获得文件路径
我认为您需要的是一个FolderBrowserDialog
,它不是WPF内置的,但可以像在这个库中一样实现: