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.

<appSettings>

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

</appSettings>

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
objConfig.Save(ConfigurationSaveMode.Modified)
ConfigurationManager.RefreshSection(“appSettings”)
End If

About these ads

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

%d bloggers like this: