2017-05-30 10 views
1

私はこの質問をどこかで解決しなければならないと確信しているので、私は躊躇していますが、私は何時間も探していて、私はすべてのノイズに溺れています。 VB.NETのための洗練されたソリューションを見つけることができません。基本的にVB.NET用のFolderDialogを改善する

、私の問題は、この質問と同じですが、VB.NETに適用される:

How do you configure an OpenFileDialog to select folders?

http://www.lyquidity.com/devblog/?p=136

誰かがクリーン/最もエレガントなソリューションを私に直接助けてくださいことはできますか?

本当にありがとうございます。

答えて

1

合意した通り、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)