Store and Retrieve last selected path of FolderBrowserDialog in app.config file

Add the following key value setting under appSettings Section in app.config file.


       <add key=”LastOpenedfolderPath” value=”D:\MyXyzFolder” />


VB.Net Code to Retrieve and Store the latest one:

Dim folderDlg As New FolderBrowserDialog

Retrieving From config file. If there is wrong path was stored in config file, it will open the default Root folder.
folderDlg.SelectedPath = ConfigurationManager.AppSettings(“LastOpenedfolderPath“).ToString()

If (folderDlg.ShowDialog() = DialogResult.OK) Then
Storing the Last opened Folder in Config File
Dim objConfig As Configuration = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None)
objConfig.AppSettings.Settings(“LastOpenedfolderPath“).Value = folderDlg.SelectedPath
End If



FolderBrowserDialog allows to create, browse and select the folder from the file system.

the SelectedPath will be a string containing the path to the selected folder.

ShowNewFolderButton property to control if the user is able to create new folders with the New Folder button.

FolderBrowserDialog is a modal dialog box; therefore, when shown, it blocks the rest of the application until the user has chosen a folder.


Dim _pathDestination As String = “”

Dim fbd As New FolderBrowserDialog
If fbd.ShowDialog() = DialogResult.OK Then

_pathDestination = fbd.SelectedPath

End If


Retrieving ip address from connectionstring of app.config file

Here is an example of  retrieving ip address from connectionstring of app.config file.

==> you must referece system.Configuration dll to your project.


imporst system.configuration

Dim connStr, serverIP As String
Dim startIndex, endIndex As Integer
serverIP = “”

connStr = ConfigurationManager.ConnectionStrings(“MyConnectionString”).ConnectionString
startIndex = connStr.IndexOf(“server=”) + 7     ‘ (server=) has 7 characters in it
endIndex = connStr.IndexOf(“;”, startIndex)
serverIP = connStr.Substring(startIndex, (endIndex – startIndex))
Catch ex As Exception
MessageBox.Show(“Error during retriving ip address”, “My Project Title”, MessageBoxButtons.OK, MessageBoxIcon.Stop)
End Try

tslblConnectedTo.Text = “Server Configuration: ” & serverIP