凡为Properties.Settings.Default数据保存? [英] Where is the data for Properties.Settings.Default saved?

查看:1171
本文介绍了凡为Properties.Settings.Default数据保存?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的WPF应用程序,我点击 Settings.settings 在解决方案资源管理器和输入 StringCollection 用户范围变量:

In my WPF application, I click on Settings.settings in the Solution Explorer and enter a StringCollection variable with a User scope:

在我的app.config我看到他们保存有:

in my app.config I see that they are saved there:

<userSettings>
    <TestSettings.Properties.Settings>
        <setting name="Paths" serializeAs="Xml">
            <value>
                <ArrayOfString xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                    xmlns:xsd="http://www.w3.org/2001/XMLSchema">
                    <string>one</string>
                    <string>two</string>
                    <string>three</string>
                    <string>four</string>
                    <string>five</string>
                    <string>six</string>
                    <string>seven</string>
                </ArrayOfString>
            </value>
        </setting>
    </TestSettings.Properties.Settings>
</userSettings>



然后我跑我的应用程序并使用此代码:

StringCollection paths = Properties.Settings.Default.Paths;

Properties.Settings.Default.Paths.Add("added in code");
Properties.Settings.Default.Save();

foreach (var path in paths)
{
    System.Console.WriteLine(path);
}



这给了我这样的输出

one
two
three
four
five
six
seven
added in code

我运行应用程序再次它给了我这样的输出:

I run the application again and it gives me this output:

one
two
three
four
five
six
seven
added in code
added in code


$ b添加$ b

不过,我看我的的app.config 再次,它仍然有在初始值

<userSettings>
    <TestSettings.Properties.Settings>
        <setting name="Paths" serializeAs="Xml">
            <value>
                <ArrayOfString xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                    xmlns:xsd="http://www.w3.org/2001/XMLSchema">
                    <string>one</string>
                    <string>two</string>
                    <string>three</string>
                    <string>four</string>
                    <string>five</string>
                    <string>six</string>
                    <string>seven</string>
                </ArrayOfString>
            </value>
        </setting>
    </TestSettings.Properties.Settings>
</userSettings>



凡被保存了由应用程序添加的价值?

推荐答案

由于您选择的用户范围,它们被保存在每个用户的配置文件目录,更具体地说,在在名为 user.config 文件中的用户配置文件的应用程序数据文件夹中。

Since you selected user scope, they are saved in each user profile directory, more specifically, inside the AppData folder of the user profile in a file named user.config.

完整路径依赖的应用程序。

The full path is dependent of the application.

在Windows 7中没有漫游配置文件,并与Windows窗体应用程序名为 Example.Settings.CustomClass 我得到以下文件夹:

In Windows 7 without roaming profile and with an Windows Forms Application named Example.Settings.CustomClass I'm getting the following folder:

C:\Users\[user]\AppData\Local\Microsoft\Example.Settings.CustomCl_Url_3qoqzcgn1lbyw2zx3oz1o3rsw2anyjsn\1.0.0.0

另外请注意,他们保存服用考虑您的应用程序的版本,并存储在的App.config 的值是用于新用户的默认值。

Also note that they are saved taking in consideration the version of your application and that the values stored in App.config are the default values used for a new user.

这篇关于凡为Properties.Settings.Default数据保存?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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