Ravindra Nadh
Ravindra Nadh

Reputation: 131

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

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

Upvotes: 2

Views: 98

Answers (1)

Glen Thomas
Glen Thomas

Reputation: 10744

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

Upvotes: 2

Related Questions