我很犹豫要问这个问题,因为我确定它必须已经在某个地方回答了,但我一直在寻找几个小时,要么我淹没在所有的噪音中,要么我根本找不到优雅VB.NET的解决方案。
基本上,我的问题与这个问题相同,但适用于VB.NET:
How do you configure an OpenFileDialog to select folders?
http://www.lyquidity.com/devblog/?p=136
有人可以帮我指导最干净/最优雅的解决方案吗?
我真的很感激。
答案 0 :(得分:2)
同意,FolderBrowserDialog
很可怕。我使用标准SaveFileDialog
,并忽略文件名。
Dim strFolder As String = ""
Using dlg As New SaveFileDialog With {.AddExtension = True,
.AutoUpgradeEnabled = True,
.CreatePrompt = False,
.OverwritePrompt = False,
.CheckFileExists = False,
.CheckPathExists = True,
.FileName = "Folder selection",
.Filter = "All files (*.*)|*.*",
.FilterIndex = 1,
.InitialDirectory = My.Computer.FileSystem.SpecialDirectories.MyDocuments,
.SupportMultiDottedExtensions = True,
.Title = "Select folder",
.ValidateNames = True}
If dlg.ShowDialog = DialogResult.OK Then
Dim strFilename As String = dlg.FileName
strFolder = System.IO.Path.GetDirectoryName(strFilename)
End If
End Using
MsgBox(strFolder)