简体   繁体   中英

How do I save custom configuration sections during runtime?

My application allows the user to add additional items to a combobox that get saved in a custom configuration section. The issue is that the save() call fails because my app is installed to C:/Program Files... which do not have read-write permissions so the user must run my app as Administrator.

Is there a more skillful way of saving user-added UI elements that persist? I looked into user settings but it doesn't seem like there is a way to save collections.

.NET doesn't really support writing to the app.config at runtime. You can do it, but you run into situations with permission. Writing to the app.config at runtime is generally an indication of user-scoped configuration. This is generally done with user-scoped configuration items within Properties.Settings which stores defaults in app.config and writes new/changes to the user's AppData.

In terms of custom configuration, with user-scoped settings, it really doesn't apply. You can simply use your own types in the Settings designer.

User settings (http://msdn.microsoft.com/en-us/library/bb397750(v=vs.90).aspx) are the best match for what you want. You could serialize the collection to JSON and save that as a string-typed setting.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM