简体   繁体   English

Properties.Settings.Default 的数据保存在哪里?

[英]Where is the data for Properties.Settings.Default saved?

In my WPF application, I click on Settings.settings in the Solution Explorer and enter a StringCollection variable with a User scope:在我的 WPF 应用程序中,我单击解决方案资源管理器中的Settings.settings并输入一个具有用户范围的StringCollection变量:

替代文字

in my app.config I see that they are saved there:在我的 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>

then I run my application and with this code:然后我运行我的应用程序并使用以下代码:

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);
}

which gives me this output :这给了我这个输出

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

But I look at my app.config again and it still has the original values :但是我再次查看我的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>

Where are the values that are added by the application being saved?应用程序添加的值在哪里保存?

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 .由于您选择了用户范围,因此它们保存在每个用户配置文件目录中,更具体地说,保存在用户配置文件的AppData文件夹中名为user.config的文件中。

The full path is dependent of the application.完整路径取决于应用程序。

In Windows 7 without roaming profile and with an Windows Forms Application named Example.Settings.CustomClass I'm getting the following folder:在没有漫游配置文件和名为Example.Settings.CustomClass的 Windows 窗体应用程序的 Windows 7 中,我得到以下文件夹:

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

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.另请注意,它们的保存考虑了您的应用程序版本,并且App.config中存储的值是用于新用户的默认值。

I was looking under Win 10 for the Settings.我在 Win 10 下寻找设置。 If anyone else need to know, they are not stored in Subfolder of Microsoft (see previous answer).如果其他人需要知道,它们不会存储在 Microsoft 的子文件夹中(请参阅上一个答案)。 Just look here:看看这里:

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

I stumbled across an easy way to find the path(s).我偶然发现了一种找到路径的简单方法。

  1. Open the Application Properties.打开应用程序属性。
  2. Under the "Application" tab, select "Assembly Information...".在“应用程序”选项卡下,选择“程序集信息...”。
  3. Change the value of "Company".更改“公司”的值。 Select OK to save.选择确定以保存。
  4. Select the "Settings" application properties tab.选择“设置”应用程序属性选项卡。
  5. Select "Synchronize" (first button in the options at the top of the tab).选择“同步”(选项卡顶部选项中的第一个按钮)。
    You should then receive a Visual Studio information dialogue saying "No user.config files were found in any of the following locations:" followed by a list of locations where the settings are saved.然后,您应该会收到一个 Visual Studio 信息对话框,提示“在以下任何位置均未找到 user.config 文件:”,然后是保存设置的位置列表。

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

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