[英]How to get list name connected usb devices to computer
我试过此代码以将USB设备连接到计算机。 这是代码:
cbbFolder.DataSource = System.IO.DriveInfo.GetDrives()
.Where(d => d.DriveType == System.IO.DriveType.Removable).ToList();
cbbFolder.DisplayMember = "Name";
cmbusb是一个组合框..在这里,我得到这个:
I:/
但没有获得设备名称,例如:
例如:USB(I :)或可移动光盘(G :)
您需要使用VolumeLabel
属性来获取Drive
的名称
尝试这个:
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";
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.