使用VB.Net可以在下拉列表中列出所有映射的网络目录/驱动器吗?
我已经护目镜但是找不到任何有用的东西..
答案 0 :(得分:7)
将其添加到DropDownList:
Private Sub TestCase1()
Dim drive As System.IO.DriveInfo
For Each drive In System.IO.DriveInfo.GetDrives()
If drive.DriveType = IO.DriveType.Network Then
DropDownList1.Items.Add(drive.Name)
End If
Next
End Sub
这就是我在C#中的表现:
private void TestCase1()
{
//Recurse through the drives on this system and add them to the new DropDownList DropDownList1 if they are a network drive.
foreach(System.IO.DriveInfo drive in System.IO.DriveInfo.GetDrives())
{
//This check ensures that drive is a network drive.
if (drive.DriveType == System.IO.DriveType.Network)
{
//If the drive is a network drive we add it here to a combobox.
DropDownList1.Items.Add(drive);
}
}
}
答案 1 :(得分:1)
Dim drive As System.IO.DriveInfo
If DropDownList1.Count < 1
For Each drive In System.IO.DriveInfo.GetDrives()
If drive.DriveType = IO.DriveType.Network Then
DropDownList1.Items.Add(drive.Name)
End If
Next
End If