long trần
long trần

Reputation: 37

How to get list name connected usb devices to computer

i have tried this code to get the usb devices in connected to the computer. This is the code:

        cbbFolder.DataSource = System.IO.DriveInfo.GetDrives()
                                .Where(d => d.DriveType == System.IO.DriveType.Removable).ToList();
        cbbFolder.DisplayMember = "Name";

cmbusb is a combobox.. here i am getting this :

I:/

but not getting the device name, like :

ex : USB(I:) or Removable Disc(G:)

Upvotes: 0

Views: 1181

Answers (1)

Sudhakar Tillapudi
Sudhakar Tillapudi

Reputation: 26209

You need to use VolumeLabel property to get the Name of the Drive

Try This:

       var divesList = System.IO.DriveInfo.GetDrives()
                            .Where(d => d.DriveType == System.IO.DriveType.Fixed).ToList();


        Dictionary<string, string> dictDrives = new Dictionary<string, string>();

        foreach(var item in divesList)
        {
            dictDrives.Add(item.Name, item.Name + " " + item.VolumeLabel);
        }
        cbbFolder.DataSource = new BindingSource(dictDrives, null);
        cbbFolder.DisplayMember = "Value";

Upvotes: 1

Related Questions