Prev: Shocking mistake with comparitor function by Microsoft programmers!
Next: sort array of strings using for loop
From: Giulio Petrucci on 5 Mar 2010 11:10 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 10 Mar 2010 08:49
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 -- |