Popular Posts

Wednesday, May 11, 2011

Reading and Writing .Net Applications Settings

Sometimes you have to deal with the .Net framework in a way or another. I was forced to use a .Net C# closed-source library. And that library was automatically reading file paths from ConfigurationManager.AppSettings[]. So, I needed a way to read and modify those settings. Fortunately, this post saved my life!

To read:
string value = ConfigurationManager.AppSettings["oldPlace"];

To modify/write:
System.Configuration.Configuration config =ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);

config.AppSettings.Settings["oldPlace"].Value = "3";

More information can be retrieved from the MSDN:

No comments: