.NET选择USB驱动器作为默认的FolderBrowserDialog路径

时间:2017-09-28 00:37:16

标签: .net vb.net path usb folderbrowserdialog

嗨,所有编程大师,

目前,通过单击按钮选择路径(文件夹)。

Private Sub SelectButton_Click(sender As Object, e As EventArgs) Handles SelectButton.Click
    FolderBrowserDialog1.ShowDialog()
    Path.Text = FolderBrowserDialog1.SelectedPath

End Sub

制作USB驱动器路径的方法有哪些默认FolderBrowserDialog.SelectedPath

谢谢!

1 个答案:

答案 0 :(得分:1)

请尝试以下代码:

    Dim folder = New FolderBrowserDialog()
    Dim drives = System.IO.DriveInfo.GetDrives()
    Dim usbDrive = drives.FirstOrDefault(Function(m) m.DriveType = System.IO.DriveType.Removable)
    folder.SelectedPath = usbDrive.RootDirectory.FullName
    If folder.ShowDialog() = DialogResult.OK Then
        MessageBox.Show(folder.SelectedPath)
    End If