how to get the folder path if no file is present in that folder using OpenFileDialog Class in WPF
{
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);
}
}
but it cant get folder path when there is no file to select
It would be impossible for the
ShowDialog()to returntrueif no file has been selected.If you set the
OpenFileDialog'sCheckFileExistsproperty totruefirst then the user can enter a file name that does not exist and then you would get the file path.I think what you need is a
FolderBrowserDialog, which is not built-in with WPF, but can be implemented like in this library: wpfdialogs