Read & Write app.config

Posted by Rodney Vinyard on Geeks with Blogs See other posts from Geeks with Blogs or by Rodney Vinyard
Published on Thu, 29 Apr 2010 23:42:44 GMT Indexed on 2010/04/29 23:58 UTC
Read the original article Hit count: 506

Filed under:

Imports System.Configuration

 

Public Class Form1

 

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

 

        Dim config As System.Configuration.Configuration = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None)

        Me.txtFromFolder.Text = ConfigurationManager.AppSettings("fromFolder")

        Me.txtToFolder.Text = ConfigurationManager.AppSettings("toFolder")

 

 

    End Sub

 

    Private Sub Form1_FormClosing(ByVal sender As System.Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles MyBase.FormClosing

 

 

        'to write

        Dim config As System.Configuration.Configuration = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None)

 

        config.AppSettings.Settings.Remove("fromFolder")

        config.AppSettings.Settings.Add("fromFolder", txtFromFolder.Text.Trim)

 

        config.AppSettings.Settings.Remove("toFolder")

        config.AppSettings.Settings.Add("toFolder", txtToFolder.Text.Trim)

 

        config.Save(ConfigurationSaveMode.Modified)

 

        ConfigurationManager.RefreshSection("appSettings")

 

    End Sub

© Geeks with Blogs or respective owner