0

I am trying to save personalized data using ApplicationSettingsBase. This was done by fetching personalized data using indexer object this[string propertyName] of ApplicationSettingBase and saving the personalized data using ApplicationSettingBase save call.

A property annotated as [UserScopedSetting] is used as personalized data which is saved and read.

The data is saved and fetched from user.config file saved in below location:

C:\Users\loggedInUser\AppData\Local\fixed string\Exe Name appeneded with hash\dll version\User.Config

Question:

Using ApplicationSettingsBase, I would like to be able to change the default path where the settings are stored.

Link questions on similar lines:

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

Sharing settings between applications

Ritesh Kumar
  • 153
  • 12
  • That link doesn't explain how to change the location of the settings files, does it? It only describes where they are stored by default according the type of application. – Isma Jul 11 '18 at 12:30
  • @Isma yes, it just tells where to look for the file. – Ritesh Kumar Jul 11 '18 at 12:34
  • @bommelding Fixing the location will solve many problems for me as i will have control on the location.One scenario, want to read the file from another exe. – Ritesh Kumar Jul 11 '18 at 12:38
  • @RiteshKumar: Did you try to use a custom provider as I suggested or what happened? – mm8 Jul 12 '18 at 12:38
  • @mm8 Not yet , but looks like this should solve...Thanks!! . Will mark it as answer once i try it out. – Ritesh Kumar Jul 12 '18 at 15:37

1 Answers1

2

You should be able to write a custom SettingsProvider class and replace the default LocalFileSettingsProvider with this one in your setting class, e.g.:

public class MyUserSettings : ApplicationSettingsBase
{
    public MyUserSettings()
        : base()
    {
        Providers.Clear();
        Providers.Add(new CustomProvider());
    }
    ...
}
mm8
  • 163,881
  • 10
  • 57
  • 88