How to check the drive is exists in the system from the given string in WPF. I have tried the following
Ex: FileLocation.Text = \"K:\\TestDriv
string drive = Path.GetPathRoot(FileLocation.Text); // e.g. K:\
if (!Directory.Exists(drive))
{
MessageBox.Show("Drive " + drive + " not found or inaccessible",
"Error", MessageBoxButton.OK);
return;
}
Of course, additional sanity checks (does the path root have at least three characters, is the second one a colon) should be added, but this will be left as an exercise to the reader.