0

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

 foreach (DriveInfo drive in DriveInfo.GetDrives())
 {
     if (drive.DriveType == DriveType.Removable)
     {
        cmbUSB.Items.Add(drive.Name);
     }
 }

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

 E:/
 G:/

but not getting the device name, like :

 E:/Insforia 

something like this, how can i get this? is it possible to get this? pls help

Arindam Das
  • 699
  • 4
  • 20
  • 39

2 Answers2

3

For getting the DeviceName of E:/ try this.

DriveInfo driveInfo = new DriveInfo("E"); 
if(driveInfo.IsReady) 
{ 
    string deviceName = driveInfo.VolumeLabel; 
} 
Murugan
  • 1,441
  • 1
  • 12
  • 22
2

I believe you are looking for VolumeLabel, try:

The label length is determined by the operating system. For example, NTFS allows a volume label to be up to 32 characters long. Note that null is a valid VolumeLabel.

foreach (DriveInfo drive in DriveInfo.GetDrives())
 {
     if (drive.DriveType == DriveType.Removable)
     {
        if (drive.IsReady)
                 cmbUSB.Items.Add(drive.Name + "-" + drive.VolumeLabel);
                                                     //^^^^^^^^^^^^^^^^
                                                     //here   
     }
 }
Habib
  • 219,104
  • 29
  • 407
  • 436