English 中文(简体)
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?

最佳回答

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.

问题回答

I was looking under Win 10 for the Settings. If anyone else need to know, they are not stored in Subfolder of Microsoft (see previous answer). Just look here:

C:Users[user]AppDataLocalExampleExample...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.




相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...

热门标签