ConfigurationManager.AppSettings - 如何修改和保存? [英] ConfigurationManager.AppSettings - How to modify and save?

查看:2180
本文介绍了ConfigurationManager.AppSettings - 如何修改和保存?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这听起来太繁琐要求和我做同样的事情在文章建议,但预期这是行不通的。希望有人能指出我朝着正确的方向。

It might sound too trival to ask and I do the same thing as suggested in articles, yet it doesn't work as expected. Hope someone can point me to the right direction.

我想救usersettings每AppSettings的。

I would like to save the usersettings per AppSettings.

在WinForm的关闭我触发此:

Once the Winform is closed I trigger this:

conf.Configuration config = 
           ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);

if (ConfigurationManager.AppSettings["IntegrateWithPerforce"] != null)
    ConfigurationManager.AppSettings["IntegrateWithPerforce"] = 
                                           e.Payload.IntegrateCheckBox.ToString();
else
    config.AppSettings.Settings.Add("IntegrateWithPerforce", 
                                          e.Payload.IntegrateCheckBox.ToString());

config.Save(ConfigurationSaveMode.Modified);

因此​​,当进入犯规还存在第一次,它只会创建它,否则它会修改现有的条目。然而,这不保存。

So the first time when the entry doesnt exist yet, it would simply create it, otherwise it would modify the existing entry. However this doesn't save.

1)我在做什么错了?

1) What am I doing wrong?

2)我在哪里期待usersettings的应用程序设置,再次保存?它是在Debug文件夹或c:\的Documents and Settings \用户名\本地设置\ Application Data文件夹

2) Where am I expecting the usersettings for App settings to be saved again? Is it in the Debug folder or in C:\Documents and Settings\USERNAME\Local Settings\Application Data folder?

推荐答案

也许你应该看看添加一个设置文件。 (例如App.Settings) 创建这个文件将允许你做到以下几点:

Perhaps you should look at adding a Settings File. (e.g. App.Settings) Creating this file will allow you to do the following:

string mysetting = App.Default.MySetting;
App.Default.MySetting = "my new setting";

这意味着您可以编辑,然后更改项目,其中项目是强类型的,并且最重要的是......你没有接触任何XML部署之前!

This means you can edit and then change items, where the items are strongly typed, and best of all... you don't have to touch any xml before you deploy!

的结果是一个应用程序或用户的上下文的设置。

The result is a Application or User contextual setting.

您可在添加新项菜单的设置文件一起来看看。

Have a look in the "add new item" menu for the setting file.

这篇关于ConfigurationManager.AppSettings - 如何修改和保存?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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