我已经尝试过此代码,以便将USB设备连接到计算机。这是代码:
cbbFolder.DataSource = System.IO.DriveInfo.GetDrives()
.Where(d => d.DriveType == System.IO.DriveType.Removable).ToList();
cbbFolder.DisplayMember = "Name";
cmbusb是一个组合框..我在这里得到这个:
I:/
但没有获取设备名称,例如:
例如:USB(I :)或可移动光盘(G:)
答案 0 :(得分:1)
您需要使用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";