1

I want to use a .NET settings file in an external dll library. This article explains exactly what I am trying to do.

partial class LastState
{
    public LastState() : base(new ConfigurationFileApplicationSettings("LastState.config", typeof(LastState))) { }
}

Unfortunately, using this implementation, it is not possible to save settings back to the config file. If I try to use Save(), SetPropertyValues throws a NotSupportedException. Is there any way to save a .NET settings file from an external dll library?

berti
  • 127
  • 1
  • 15

1 Answers1

3

I would use custom configuration files.

ExeConfigurationFileMap configMap = new ExeConfigurationFileMap();
configMap.ExeConfigFilename = @"d:\test\justAConfigFile.config.whateverYouLikeExtension";
Configuration config = ConfigurationManager.OpenMappedExeConfiguration(configMap, ConfigurationUserLevel)

Have a look here for more détails.

You can save with

config.AppSettings.Settings["YourThing"].Value = "New Value";
config.Save(); 
Community
  • 1
  • 1
Eric Bole-Feysot
  • 13,949
  • 7
  • 47
  • 53