如何修复user.config文件的位置以进行个性化设置

时间:2018-07-11 12:24:05

标签: c# .net xml wpf

我正在尝试使用ApplicationSettingsBase保存个性化数据。这是通过使用object this[string propertyName]的索引器ApplicationSettingBase获取个性化数据并使用ApplicationSettingBase保存调用保存个性化数据来完成的。

注释为[UserScopedSetting]的属性用作保存和读取的个性化数据。

数据已保存并从保存在以下位置的user.config文件获取:

C:\ Users \ loggedInUser \ AppData \ Local \ 固定字符串 \ Exe名称带有哈希值 \ dll版本< / strong> \ User.Config

问题:

我想使用ApplicationSettingsBase来更改存储设置的默认路径。

在相似的行上链接问题:

When using a Settings.settings file in .NET, where is the config actually stored?

Sharing settings between applications

1 个答案:

答案 0 :(得分:0)

您应该能够编写一个自定义的SettingsProvider类,并在您的设置类中将其替换为默认的LocalFileSettingsProvider,例如:

public class MyUserSettings : ApplicationSettingsBase
{
    public MyUserSettings()
        : base()
    {
        Providers.Clear();
        Providers.Add(new CustomProvider());
    }
    ...
}