tags:

views:

434

answers:

3

I want to centrally locate all of my application settings in the database. I have a database object which stores the app.settings in an XML column. I'd like to have my application read that object and then parse the XML column into its own app settings. Is there any easy way to arbitrarily read an XML object into your current appsettings?

A: 

I dont know if you can alter the appsettings in runtime what i do know you can do is create the appsettings section like shown here and have a relay application that loads the correct xml for you appsettings save the file and then launch the desire application.

Oscar Cabrero
A: 

That may be possible, but in case it is not, what I like to do here is:

  1. Never directly call ConfigurationaManager - wrap all that stuff into a custom Settings class and call that instead.
  2. Then you can put your settings wherever you want and change strategies flexibly. You can make each setting a row in a database table, use normal web.config appsettings, or switch ti some other method down the road.
Brian MacKay
A: 

Read the object from your XML object, and then through your code you can save your config file as :

Configuration configFile = WebConfigurationManager.OpenWebConfiguration("~");

AppSettingsSection AppSection = configFile.GetSection("appSettings") as AppSettingsSection;

AppSection.Settings.Add( new KeyValueConfigurationElement("SMTP", "mail.bhaidar.net") );

configFile.Save();

The above code would add the following line to the appSettings section.

< appSettings >

< add key="SMTP" value="mail.bhaidar.net" / >

< / appSettings >

Samiksha