如何在运行时保存自定义配置部分? [英] How do I save custom configuration sections during runtime?

查看:95
本文介绍了如何在运行时保存自定义配置部分?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用程序允许用户将其他项目添加到组合框,并保存在自定义配置部分中.问题是save()调用失败,因为我的应用程序已安装到C:/Program Files ...,该文件没有读写权限,因此用户必须以管理员身份运行我的应用程序.

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.

是否存在保存用户添加的持久化UI元素的更熟练的方法?我调查了用户设置,但似乎没有办法保存收藏集.

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确实不支持在运行时写入app.config.您可以执行此操作,但是遇到许可情况.在运行时写入app.config通常表示用户范围的配置.通常,这是通过Properties.Settings中的用户作用域配置项完成的.Settings将默认值存储在app.config中,并将新的/更改写入用户的AppData.

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

这篇关于如何在运行时保存自定义配置部分?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆