Kamran Ahmed
Kamran Ahmed

Reputation: 12428

C# code showing multiple removeable drives window 8

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.

Upvotes: 1

Views: 259

Answers (1)

internals-in
internals-in

Reputation: 5038

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

Upvotes: 1

Related Questions