D
Devon_Nullman
Guest
Please paste this code into a form after adding 3 buttons and a Text Box:
Code
Option Strict On
Public Class Form1
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Using FBD As New FolderBrowserDialog
FBD.Description = "Choose the Folder for Your Data, License and Logs"
FBD.RootFolder = System.Environment.SpecialFolder.CommonDocuments
FBD.ShowNewFolderButton = True
If FBD.ShowDialog = DialogResult.OK Then
TextBox1.Text = FBD.SelectedPath
End If
End Using
End Sub
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
Using OFD As New OpenFileDialog
OFD.InitialDirectory = System.Environment.GetFolderPath(Environment.SpecialFolder.CommonDocuments)
OFD.Title = "Locate the Data File"
OFD.Filter = "Text Files (*.txt)|*.txt"
If OFD.ShowDialog = DialogResult.OK Then
TextBox1.Text = OFD.FileName
End If
End Using
End Sub
Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
Using SFD As New SaveFileDialog
SFD.Title = "Choose a Save File Name"
SFD.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.CommonDocuments)
SFD.OverwritePrompt = False
SFD.Filter = "Text Files (*.txt)|*.txt"
If SFD.ShowDialog = DialogResult.OK Then
TextBox1.Text = SFD.FileName
End If
End Using
End Sub
Private Sub Form1_Shown(sender As Object, e As EventArgs) Handles Me.Shown
Button1.Text = "Folder"
Button2.Text = "Open"
Button3.Text = "Save"
End Sub
End Class
Form:
Here using latest VS2017, the FolderBrowser shows the correct folder:
The OpenfileDialog shows "My Documents"
So does the SaveFileDialog
Am I missing something or making an error in the code ?
If I add this line to the open & save dialogs:
TextBox1.Text = System.Environment.GetFolderPath(Environment.SpecialFolder.CommonDocuments)
It shows correctly as "C:\Users\Public\Documents"
Continue reading...
Code
Option Strict On
Public Class Form1
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Using FBD As New FolderBrowserDialog
FBD.Description = "Choose the Folder for Your Data, License and Logs"
FBD.RootFolder = System.Environment.SpecialFolder.CommonDocuments
FBD.ShowNewFolderButton = True
If FBD.ShowDialog = DialogResult.OK Then
TextBox1.Text = FBD.SelectedPath
End If
End Using
End Sub
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
Using OFD As New OpenFileDialog
OFD.InitialDirectory = System.Environment.GetFolderPath(Environment.SpecialFolder.CommonDocuments)
OFD.Title = "Locate the Data File"
OFD.Filter = "Text Files (*.txt)|*.txt"
If OFD.ShowDialog = DialogResult.OK Then
TextBox1.Text = OFD.FileName
End If
End Using
End Sub
Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
Using SFD As New SaveFileDialog
SFD.Title = "Choose a Save File Name"
SFD.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.CommonDocuments)
SFD.OverwritePrompt = False
SFD.Filter = "Text Files (*.txt)|*.txt"
If SFD.ShowDialog = DialogResult.OK Then
TextBox1.Text = SFD.FileName
End If
End Using
End Sub
Private Sub Form1_Shown(sender As Object, e As EventArgs) Handles Me.Shown
Button1.Text = "Folder"
Button2.Text = "Open"
Button3.Text = "Save"
End Sub
End Class
Form:
Here using latest VS2017, the FolderBrowser shows the correct folder:
The OpenfileDialog shows "My Documents"
So does the SaveFileDialog
Am I missing something or making an error in the code ?
If I add this line to the open & save dialogs:
TextBox1.Text = System.Environment.GetFolderPath(Environment.SpecialFolder.CommonDocuments)
It shows correctly as "C:\Users\Public\Documents"
Continue reading...