From: Giulio Petrucci on
Hi there,

I've defined a 'Foo' configuration section in my App.config file:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<section name="Foo" type="FooLib.FooConfigSection, FooLib"></section>
</configSections>
<Foo label="Foo Label"></Foo>
</configuration>

....and defined a custom ConfigSection class:

public class FooConfigSection : ConfigurationSection
{
[ConfigurationProperty("label", IsRequired=true)]
public string Label
{
get { return (string)base["label"]; }
set { base["label"] = value; }
}
public override bool IsReadOnly() { return false; }
}

....which is used in the following code:

FooConfigSection fcs =
(FooConfigSection)ConfigurationManager.GetSection("Foo");
fcs.Label = "*";
Configuration c =
ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
c.Save(ConfigurationSaveMode.Full);

*but* nothing happens to the config file.
Could anyone help me?

Thanks in advance,
Giulio
--

From: Giulio Petrucci on
Hi there,

Giulio Petrucci wrote:
> FooConfigSection fcs =
> (FooConfigSection)ConfigurationManager.GetSection("Foo");
> fcs.Label = "*";
> Configuration c =
> ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
> c.Save(ConfigurationSaveMode.Full);

Solved:

FooConfigSection fcs =
(FooConfigSection)ConfigurationManager.GetSection("Foo");
fcs.SectionInformation.ForceSave = true; //missing line. :-)
fcs.Label = "*";
Configuration c =
ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
c.Save(ConfigurationSaveMode.Full);

HTH,
Giulio
--