2

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 Answer 1

2

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.