Come verificare l'unità è presente nel sistema dalla stringa specificata in WPF. Ho provato quanto segueVerifica unità esistente (percorso stringa)
Es:FileLocation.Text = "K:\TestDrive\XXX";
if (!Directory.Exists(FileLocation.Text))
{
MessageBox.Show("Invalid Directory", "Error", MessageBoxButton.OK);
return;
}
sta controllando percorso completo ma it should check "K:\" from the text
. La prego di guidarmi
EDIT 1: "K: \ TestDrive \ XXX" non è statica
EDIT 2: ho provato il basso, nel mio sistema che sto avendo 3 drives C, D and E
ma mostra false.
Environment.SystemDirectory.Contains("D").ToString(); = "False"
Assicurati che i tuoi campioni abbiano un codice C# ragionevole. Cioè '" K: \ Test ... "' è una costante di stringa un po 'sospetta: dovrebbe essere '@" K: \ Test ... "' o '" K: \\ Test ... "', controllando la presenza di 'true'/'false' non richiede la chiamata per' ToString' e sicuramente non il confronto tra maiuscole e minuscole con strano '; = 'operatore. –
@AlexeiLevenkov: Grazie per il tuo commento, ma ho appena dato per esempio – Ponmalar
Come su 'Directory.Exists (Path.GetPathRoot (pathGoesHere)) '? – Alxandr