[英]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).我偶然发现了一种找到路径的简单方法。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.