Smithers wrote:
2. If you want to programmaticall y write (in addition to reading), then you
have to go the more complex route presented in the links I gave earlier and
discussed below.
If you use Visual Studio 2005 you can just right-click on a project's
Properties node and select Open. Then go to the Settings tab. Just type
in you new setting's name and a default value. If you make the setting
application-copied then it cannot be written to; if you make the setting
user-scoped it can be written to easily.
VS will generate a Settings.cs file with a Settings class in it. To use
this just do this:
using <your-namespace>.Prop erties;
int maxLoops = Settings.Defaul t.MaxLoops;
// You can now use maxLoops as you would like.
Settings.Defaul t.MaxLoops = 154;
Settings.Defaul t.Save();
// You've just changed the MaxLoops setting to be 154.
This doesn't read and/or write to the <appSettingssec tion but is great
for adding user- or application-specific settings right in your class
library and/or application. But these VS-supported settings are wicked
simple to use and very flexible (say you're working on a class library,
the settings for that library can easily be copied to an app.config for
tailoring by code that uses the class library).
I decided to go through the pain of converting all my .NET 1.1 and prior
based ConfigurationSe ttings stuff to this new technique because the new
stuff didn't seem to be worth figuring out giving the VS built-in
support for the new settings. If MS does a wholesale change of the
"settings architecture" again I'm sticking with this one introduced in
..NET 2.0 - [obsolete] or not!
--
-glenn-