Frage

Below is the C# code that I'm using to get all the removeable drives and then populate the combobox with this list:

comboBox1.DataSource = DriveInfo.GetDrives()
                .Where(drive => drive.DriveType == DriveType.Removable).ToList();

The code works perfectly but with one exception, it shows two removable drives in the combo box while I've attached only one.

Is there any way that I can get only one i.e. the one I've attached at the USB port. I'm using Windows 8 OS.

War es hilfreich?

Lösung

Use drive.IsReady

Hopes you are making Removal Drive Security!!!!

Try this

 comboBox1.DataSource = DriveInfo.GetDrives()
            .Where(drive => drive.DriveType == DriveType.Removable && drive.IsReady).ToList()

thanks

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top