문제

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.

도움이 되었습니까?

해결책

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

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top