c# - Persist application scope settings -
i have application level settings windows form, can read using properties.settings.default.offset
. wanted persist these settings, these settings can used later.
as per this post @ so, tried following-
properties.settings.default["offset"] = this.offsettextbox.text; properties.settings.default.save();
but not saving value, since can see old value after changing it.
per documentation, inspection of generated code , question, "why application settings not getting persisted?", application-scoped settings read-only.
to update application-scoped settings, you'll need change appropriate <appsettings>
value in app.config
file:
- update app.config system.net setting @ runtime
- http://chiragrdarji.wordpress.com/2008/09/25/how-to-change-appconfig-file-run-time-using-c/
note change app.config
file supposed restart app domain, trying update own app.config
may behave little differently might expect.
also note changes made generated *.exe.config
file in bin
directory, not app.config
file in visual studio solution.
another thing consider: in deployed application, unless run "elevated privileges", you're unlikely have write access app.config
file.
if want persist/update sort of app settings, take page os x book , create *.plist
:
on application start, check xml file settings in known location app has read/write access. in os x, app-level settings live in
/library/preferences
; user level preferences live in~/library/preferences
.if doesn't exist, create it, populating default values settings in question (which simple copying
<appsettings>
elementapp.config
.read app-level settings file.
place
filesystemwatcher
on file hook changes , update settings.
there go. now, can update app-level settings heart's content. if ever need revert, have blow away *.plist
file.
Comments
Post a Comment