Saving settings in Properties.Settings.Default and Registry

What is the difference between saving user settings for an application in

Properties.Settings.Default

compared to storage in the registry:

HKEY_CURRENT_USER\Software\{Application Name}

+5
source share
4 answers

The difference is that the registry, well, the registry. While Properties.Settings.Default stores the configuration file in your AppData directory.

I personally do not like working with the registry at all. This is just a phobia that I left after the Windows 98 era. In any case, this is not a very pleasant registry experience. Key names are ugly and there are many possibilities for chaos.

+3
source

Properties.Settings.Default

. , Microsoft , System.Configuration, ().

Properties.Settings.Default , ApplicationSettingBase, . , [UserScopedSetting], XML C:\Users\user\AppData\Local\ComapnyName\Hashed_AppName\version, . , [ApplicationScopedSetting], app.config .

:

class FormSettings : ApplicationSettingsBase
{
    public WindowSettings() {}
    public WindowSettings(string settingsKey) : base(settingsKey) {}

    [UserScopedSettingAttribute()]
    [DefaultSettingValueAttribute("MyDefaultName")]
    public String Name
    {
        get { return (string)(this["Name"]); }
        set { this["Name"] = value; }
    }
}

Properties.Settings.Default , " " → "" "" Properties.Settings.Default.

, , . . Wikipedia.

Microsoft.Win32.Registry, . :

public class RegistryExample 
{
    public static void Main()
    {
        const string rootUser = "HKEY_CURRENT_USER";
        const string subkey = "RegistryExample";
        const string keyName = String.Format("{0}\\{1}, userRoot, subkey);

        Registry.SetValue(keyName, "MyRegistryValue", 1234);
    }
}

. MSDN. , , , , "" , , .

+2

codehill.com:

, .NET Framework INI Windows. .NET Framework XML . .exe.config, . , , , INI Windows.

+1

, Properties.Settings.Default - .

The registry does not work. You are not sure if the user who uses your application has sufficient rights to write to the registry.

0
source

All Articles