ConfigurationManager

  • Thread starter Thread starter Johnny Jörgensen
  • Start date Start date
J

Johnny Jörgensen

I don't get the ConfigurationManager object. All I want to do is store my
application settings and retrieve them on the next run.

I instantiate the Configuration:

static private Configuration m_Config =
ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);


I check if my setting exists:

try //kolla om Settings finns och skapa dem om de inte finns

{ string testSetting =
Utils.GlobalVars.FoBSettings.AppSettings.Settings["LokalServer"].Value; }

catch

{

m_Config.AppSettings.Settings.Add("LokalServer", "");

}


I change it if needed:

m_Config.AppSettings.Settings["LokalServer"].Value = "MyTestServer");


And I save the entire configuration file:

m_Config.Save(System.Configuration.ConfigurationSaveMode.Full);


Still, the next time I run the application, the LokalServer setting is Null
in AppSettings. Nothing is saved.

Why? What am I missing.


Cheers,
Johnny J.
 
I just found out that it works when I run the exe file directly, but NOT
when I run the program from the IDE - how can that be?

Cheers,
Johnny J.
 
Well, when you run from the IDE, or do a build, it is probably copying
over the app.config file in your project every time, which is causing the
values to reset.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Johnny Jörgensen said:
I just found out that it works when I run the exe file directly, but NOT
when I run the program from the IDE - how can that be?

Cheers,
Johnny J.



Johnny Jörgensen said:
I don't get the ConfigurationManager object. All I want to do is store my
application settings and retrieve them on the next run.

I instantiate the Configuration:

static private Configuration m_Config =
ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);


I check if my setting exists:

try //kolla om Settings finns och skapa dem om de inte finns

{ string testSetting =
Utils.GlobalVars.FoBSettings.AppSettings.Settings["LokalServer"].Value; }

catch

{

m_Config.AppSettings.Settings.Add("LokalServer", "");

}


I change it if needed:

m_Config.AppSettings.Settings["LokalServer"].Value = "MyTestServer");


And I save the entire configuration file:

m_Config.Save(System.Configuration.ConfigurationSaveMode.Full);


Still, the next time I run the application, the LokalServer setting is
Null in AppSettings. Nothing is saved.

Why? What am I missing.


Cheers,
Johnny J.
 
Back
Top