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:

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:

  1. 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> element app.config.

  2. read app-level settings file.

  3. 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

Popular posts from this blog

android - Get AccessToken using signpost OAuth without opening a browser (Two legged Oauth) -

org.mockito.exceptions.misusing.InvalidUseOfMatchersException: mockito -

google shop client API returns 400 bad request error while adding an item -