Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
221 views
in Technique[技术] by (71.8m points)

c# - 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:

alt text

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>

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:

<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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.

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]AppDataLocalMicrosoftExample.Settings.CustomCl_Url_3qoqzcgn1lbyw2zx3oz1o3rsw2anyjsn1.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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...