简体   繁体   English

C#应用程序设置未保存

[英]c# application setting not saved

Using VS2010 Express , Win7-64. 使用VS2010 ExpressWin7-64。 In my application I Have several Application settings. 在我的应用程序中,我有几个应用程序设置。 Most (mixed types) are User Settings, one is Application Setting (a DataSet). 大多数(混合类型)是用户设置,一种是应用程序设置(数据集)。

I use the built-in Settings table where the one setting scope is set as Application, while the others scope is User. 我使用内置的“设置”表,其中一个设置范围设置为“应用程序”,另一个设置范围设置为“用户”。 The User settings are all saved and retrieved OK, and can also be seen in the XML file. 用户设置全部保存并检索确定,并且还可以在XML文件中看到。

(string userConfig = ConfigurationManager.OpenExeConfiguration(
                  ConfigurationUserLevel.PerUserRoamingAndLocal).FilePath;)

Problem: While the User settings are saved OK, the one Application Setting is not saved and is not present in the relevant config file. 问题:在用户设置保存好的情况下,一个应用程序设置未保存并且在相关的配置文件中不存在。

(string appConfig = ConfigurationManager.OpenExeConfiguration(
                  ConfigurationUserLevel.None).FilePath;).

In the Settings.Design file we can see the Application Setting as read-only item (get only), which is OK, but no data is saved, and no data is found, (except a null DataSet). Settings.Design文件中,我们可以看到“应用程序设置”为只读项(仅获取),可以,但是没有保存任何数据,也没有找到任何数据(空数据集除外)。

There is similar DataSet in the User settings that is saved OK, and can be loaded. 用户设置中有类似的数据集,可以保存并可以加载。

To save the settings, I run: 要保存设置,我运行:

Properties.Settings.Default.Upgrade();
Properties.Settings.Default.Save();

Thanks 谢谢

Application-scope settings are read only, and can only be changed at design time. 应用程序作用域设置是只读的,只能在设计时更改。 so when you call save method it does not persist the data. 因此,当您调用save方法时,它不会保留数据。

User-scope settings, however, can be written at run time, just as you would change any property value. 但是,用户范围设置可以在运行时写入,就像您更改任何属性值一样。

for more information you can see Using Settings in C# . 有关更多信息,请参见在C#中使用设置

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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