FPG*_*PGA 8 vb.net directory file openfiledialog
在我的应用程序的第一次启动时,我需要指定一个路径来保存一些文件.但在打开文件对话框中,似乎我必须选择要打开的文件.我怎样才能指定一个文件夹而不用像C:\ config \那样选择文件
这是我的代码
If apppath = "" Then
Dim fd As OpenFileDialog = New OpenFileDialog()
fd.Title = "Select Application Configeration Files Path"
fd.InitialDirectory = "C:\"
fd.Filter = "All files (*.*)|*.*|All files (*.*)|*.*"
fd.FilterIndex = 2
fd.RestoreDirectory = True
If fd.ShowDialog() = DialogResult.OK Then
apppath = fd.FileName
End If
My.Computer.FileSystem.WriteAllText(apppath & "apppath.txt", apppath, False)
End If
Run Code Online (Sandbox Code Playgroud)
我需要选择一个文件才能使它工作,但我只想选择一个文件夹.那么解决方案是什么?
Ste*_*art 17
您想使用FolderBrowserDialog类而不是OpenFileDialog类.您可以在此处找到有关它的更多信息:
http://msdn.microsoft.com/en-us/library/system.windows.forms.folderbrowserdialog(v=vs.110).aspx
例如,你可以这样做:
If apppath = "" Then
Dim dialog As New FolderBrowserDialog()
dialog.RootFolder = Environment.SpecialFolder.Desktop
dialog.SelectedPath = "C:\"
dialog.Description = "Select Application Configeration Files Path"
If dialog.ShowDialog() = Windows.Forms.DialogResult.OK Then
apppath = dialog.SelectedPath
End If
My.Computer.FileSystem.WriteAllText(apppath & "apppath.txt", apppath, False)
End If
Run Code Online (Sandbox Code Playgroud)