How do I save custom configuration sections during runtime?

穿精又带淫゛_ 提交于 2019-12-11 04:33:56

问题


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.


回答1:


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




回答2:


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.



来源:https://stackoverflow.com/questions/12306130/how-do-i-save-custom-configuration-sections-during-runtime

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!