can we use Configuration, ConfigurationManager in Vb.net

remya1000

Well-known member
Joined
Mar 29, 2007
Messages
122
Programming Experience
Beginner
i'm using VB.NET 2003.

Last time while i did a program in Vb.Net 2005, i use "Configuration". and i could read and write to that XML configuration file like the example below.


Imports System.Configuration

Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSave.Click

Dim config As Configuration

config = ConfigurationManager.OpenExeConfiguration(Application.StartupPath + "\Program1.exe")
config.AppSettings.Settings.Remove("inactivity")
config.AppSettings.Settings.Add("inactivity", udInactivity.Value.ToString())

If (axChkterminals.Checked = True) Then
config.AppSettings.Settings.Remove("chkallterminals")
config.AppSettings.Settings.Add("chkallterminals", str)
Else
config.AppSettings.Settings.Remove("chkallterminals")
config.AppSettings.Settings.Add("chkallterminals", str)
End If

If (axChkMonday.Checked = True) Then
str = "monday" + "," + udHoursMonday.Value.ToString() + "," + udMinsMonday.Value.ToString() + "," + udHoursToMonday.Value.ToString() + "," + udMinsToMonday.Value.ToString()
config.AppSettings.Settings.Remove("monday")
config.AppSettings.Settings.Add("monday", str)
Else
config.AppSettings.Settings.Remove("monday")
End If

If (MessageBox.Show("Are you sure you want to save?", "Calendar", MessageBoxButtons.YesNo, MessageBoxIcon.Question) = Windows.Forms.DialogResult.Yes) Then
config.Save()
MessageBox.Show("Configuration File has been saved!")
End If

End Sub



Public Function LoadConfigValues() As String
Dim config As Configuration

config = ConfigurationManager.OpenExeConfiguration(Application.StartupPath + "\Program1.exe")

inactivityTime = Convert.ToDecimal(config.AppSettings.Settings("inactivity").Value)

CheckAllTerminals = Convert.ToDecimal(config.AppSettings.Settings("chkallterminals").Value)

day = config.AppSettings.Settings("monday").Value.ToString().ToLower()
If (day.Split(splitter)(0).ToLower() = "monday") Then
config_DaysList.Remove("monday")
config_DaysList.Add("monday", day)
End If

End Function

And the same type of program i need to do now in Vb.net 2003. but i can use Configuration inside 2003. when i tried to add reference instead of "System.Configuration" its "System.configuration.install". and i add that and tried the same codes above to my Vb.net 2003 program.

but in this lines error occurs as Type expected.
Dim config As Configuration

and in this lines error occurs as Name 'ConfigurationManager' is not declared.
config = ConfigurationManager.OpenExeConfiguration(Application.StartupPath + "\Program1.exe")

whether i can use "Configuration" in 2003.if you have anyidea what's wrong please let me know. if you can please help me.

Thanks in advance.
 
Back
Top