Storing Application Settings
-
What's the best way of storing an application setting to read it later? Do I have to resort to a text file or is there some better way with .NET 2.0?
-
What's the best way of storing an application setting to read it later? Do I have to resort to a text file or is there some better way with .NET 2.0?
I would store them in the app.config file. // Get the application configuration file. System.Configuration.Configuration config = ConfigurationManager.OpenExeConfiguration( ConfigurationUserLevel.None); ///Make changes to the config file. Perhaps in someplace like appSettings //then save config.Save(); Hope that helps. Ben
-
What's the best way of storing an application setting to read it later? Do I have to resort to a text file or is there some better way with .NET 2.0?
Depends on your needs. If it's simple data, use an App.config or the Web.config if you're doing a web app. You can just add keys to them which are easy enough to retrieve.
<configuration>
<appSettings>
<add key="field" value="1" />
</appSettings>
...
</configuration>Then in code you can access them with something like...
string field = System.Configuration.ConfigurationSettings.AppSettings("field");
But if you have more complex data that you need to store, I usually do my own XML structure and use something like Skeleton Crew[^] to build a code model to use it with.
Try code model generation tools at BoneSoft.com.