Can app.config be updated by the user?

D

Dean Slindee

I store several application settings in the project's "app.config" file. I
also have a form that reads these values and displays them in a listview so
that the user can adjust them. My question is: can the changes made by the
user to the settings values be saved back to "app.config" so that when the
application is launched tomorrow, the updated values are used?

Since the original app.config settings are loaded to
"projectName.exe.config", and updated there by the user, another way of
asking the same question is: how to write the values in
"projectName.exe.config" back to "app.config"?

Thanks,
Dean Slindee
 
L

Lucas Tam

My question is: can the changes made by the
user to the settings values be saved back to "app.config" so that when
the application is launched tomorrow, the updated values are used?

No, the config files are read only, You'll need to write your own XML
classes to update the configs.
 
T

Tom Dacon

Microsoft 'prefers' that the app.config file be considered a read-only
application initialization repository. For one thing, since there's only one
file for the application it's machine-wide rather than user-specific. Thus
it's not a good place for user-specific preferences. Probably the best place
to store user preferences is in your own XML files, either in user-specific
isolated storage, or in the directory represented by
Application.UserAppDataPath.

Quite a few people, by now, have created libraries for managing user
preferences in XML files (I've certainly done it for my own personal use).
It's a shame that MS didn't supply wrapper classes for this in the
framework, since we're all having to re-invent the wheel on this. If you
look around places like www.gotdotnet.com or www.sourceforge.net you'll
undoubtedly come across one or more solutions to this problem that have been
contributed by that community. I haven't contributed my own, since I doubt
that the world needs another one.

Tom Dacon
Dacon Software Consulting
 
T

Tom Dacon

I should also add, as a disadvantage of trying to write into the app.config
file, that you can't guarantee that the user of the application will have
write permissions on the directory in which the application executable and
the config file reside. A system administrator might lock that directory
down, causing your application to fail with a permissions exception when you
tried to write to the file.

Tom Dacon
 
S

scorpion53061

TO write settings via an xml file:

http://www.kjmsolutions.com/xmlsettings.htm

To write settings to an app.config file....(not recommended)

http://www.kjmsolutions.com/downloads/appconfigstuff.ZIP

to use Isolated storage..(must have adequate .NET permissions..)

http://www.kjmsolutions.com/downloads/appconfigsystemio.ZIP

________________________________

From: Dean Slindee [mailto:[email protected]]
Sent: Saturday, August 21, 2004 11:20 PM
To: microsoft.public.dotnet.languages.vb
Subject: Can app.config be updated by the user?



I store several application settings in the project's "app.config" file.
I
also have a form that reads these values and displays them in a listview
so
that the user can adjust them. My question is: can the changes made by
the
user to the settings values be saved back to "app.config" so that when
the
application is launched tomorrow, the updated values are used?

Since the original app.config settings are loaded to
"projectName.exe.config", and updated there by the user, another way of
asking the same question is: how to write the values in
"projectName.exe.config" back to "app.config"?

Thanks,
Dean Slindee
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top