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
You can use Environment.GetLogicalDrives()
to obtain an string[]
of logical drives in your system.
var drive = Path.GetPathRoot(FileLocation.Text);
if (Environment.GetLogicalDrives().Contains(drive, StringComparer.InvariantCultureIgnoreCase))
{
MessageBox.Show("Invalid Directory", "Error", MessageBoxButton.OK);
return;
}