ConfigurationManager

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.
 
J

Johnny Jörgensen

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.
 
N

Nicholas Paldino [.NET/C# MVP]

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top