vb.net – 在下拉列表中获取所有映射的网络驱动器

前端之家收集整理的这篇文章主要介绍了vb.net – 在下拉列表中获取所有映射的网络驱动器前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
使用VB.Net是否可以在下拉列表中列出所有映射的网络目录/驱动器?

我有眼罩,但找不到任何有用的东西..

要将它添加到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);
            }
        }
    }

猜你在找的VB相关文章