Writing in .config XML application configuration file.

  • Thread starter Thread starter msnews.microsoft.com
  • Start date Start date
M

msnews.microsoft.com

Hi all,

I was trying to find an easy way to write in the standard configuration
(like app.config) xml-based files. I found classes that can be used to read
this information (in System.Configuration) like the
ConfigurationSettings.AppSettings property, but I was not able to find
anything to write app settings in these files. Isn't this kind of
"asymmetrical"? Anyone familiar with the reasons of such a lack?

Thanks a lot,

Ivan Ivanov
 
Hello,

msnews.microsoft.com said:
I was trying to find an easy way to write in the standard
configuration (like app.config) xml-based files. I found
classes that can be used to read this information
(in System.Configuration) like the ConfigurationSettings.
AppSettings property, but I was not able to find
anything to write app settings in these files. Isn't this kind of
"asymmetrical"? Anyone familiar with the reasons of such a lack?

config files should not be modified by the application, that's why there
are no methods available for modifying them. Nevertheless, you can use
the XML classes provided by the framework to make changes to the config
files.

The config file should not be used to save user preferences. You can
use something like this instead:

http://www.palmbytes.de/content/dotnet/optionslib.htm
 
For personal settings, it appears that MS recommends that you maintain a
separate file to hold them. The official story for the app config file is
that it's intended to be read-only and to contain more or less invariant
application settings, independent of any user preferences. You can use a
separate XML file, for instance, to maintain user preferences. I'd suggest
that you consider keeping such a file in isolated storage (see the
IsolatedStorage class for details).

Tom Dacon
Dacon Software Consulting
 
I agree with all of the above. You can find the reasons why app.config files
are not writable in the the Windows Logo Requirements [0]. However, you can
still leverage the same programming model for user specific settings if you
intergrate Microsoft's Confiuration Management Application Block [1].

--
HTH
Christoph Schittko [MVP]
Software Architect, .NET Mentor

[0] http://www.microsoft.com/winlogo/software/tech_req.mspx
[1]
http://www.gotdotnet.com/Community/Workspaces/Workspace.aspx?id=01875f69-9358-437b-a8ae-fa4bf2e3080f
 
Thanks a lot for the input.

I did not mean that I want to necessarily write in the app.config file. I
was looking for .net support for writing user settings in any kind of .ini -
like file (or registry settings for that matter, even though MS does not
recommend using the registry now!). I know that I can use XMLReaders and
such but I was looking for a 1 - line solution like good old
WritePriveteProfileString or so.

Thanks,

Ivan

Christoph Schittko said:
I agree with all of the above. You can find the reasons why app.config files
are not writable in the the Windows Logo Requirements [0]. However, you can
still leverage the same programming model for user specific settings if you
intergrate Microsoft's Confiuration Management Application Block [1].

--
HTH
Christoph Schittko [MVP]
Software Architect, .NET Mentor

[0] http://www.microsoft.com/winlogo/software/tech_req.mspx
[1]
http://www.gotdotnet.com/Community/Workspaces/Workspace.aspx?id=01875f69-9358-437b-a8ae-fa4bf2e3080f
msnews.microsoft.com said:
Hi all,

I was trying to find an easy way to write in the standard configuration
(like app.config) xml-based files. I found classes that can be used to read
this information (in System.Configuration) like the
ConfigurationSettings.AppSettings property, but I was not able to find
anything to write app settings in these files. Isn't this kind of
"asymmetrical"? Anyone familiar with the reasons of such a lack?

Thanks a lot,

Ivan Ivanov
 
I did not mean that I want to necessarily write in the app.config file. I
was looking for .net support for writing user settings in any kind of .ini -
like file (or registry settings for that matter, even though MS does not
recommend using the registry now!). I know that I can use XMLReaders and
such but I was looking for a 1 - line solution like good old
WritePriveteProfileString or so.

There are three classes devoted to simplifying registry access, by the
way. Check out the System.Microsoft.Win32 namespace.
 
Back
Top