Click to See Complete Forum and Search --> : can we use Configuration, ConfigurationManager in Vb.net 2003


remya1000
09-27-2007, 03:58 PM
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.

Cstick
09-29-2007, 11:25 PM
Simply put, configurationManager is not available in VS 2003 (.Net Framework 1.1). It was introduced in VS 2005 (.Net Framework 2.0) and replaces the System.Configuration.configurationsettings which is now depricated.