Pregunta

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

¿Fue útil?

Solución 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   
     }
 }

Otros consejos

For getting the DeviceName of E:/ try this.

DriveInfo driveInfo = new DriveInfo("E"); 
if(driveInfo.IsReady) 
{ 
    string deviceName = driveInfo.VolumeLabel; 
} 
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top