folder path when it has no files using OpenFileDialog in WPF?

92 Views Asked by At

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

1

There are 1 best solutions below

0
Glen Thomas On

It would be impossible for the ShowDialog() to return true if no file has been selected.

If you set the OpenFileDialog's CheckFileExists property to true first 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