Using information provided in the questions: How do I save a configuration file with a custom configuration section? and Saving custom section to config file I came up to helper method which I add to my ConfigurationSection
type:
public void SaveAs(string path)
{
this.SectionInformation.ForceSave = true;
System.Configuration.Configuration configRoot = ConfigurationManager.OpenExeConfiguration(null);
configRoot.Sections.Add(GetSectionName(), this);
// *
configRoot.SaveAs(path, ConfigurationSaveMode.Full);
}
Well, the file is created, the section is saved, the problem is all the values are default ones, not actual. At the point marked with asterisk I checked my data, both this
object contains actual value I would like to see and peeking inside configRoot
I can see it has several sections at this point, there is mine as well, and it contains the correct values. Yet one thing is kept (actual values), the other thing is saved (defaults).
So, how to save the all data, actual data from given ConfigurationSection
?
When I change the saving mode to ConfigurationSaveMode.Modified
the correct values are saved, but only the the ones I modified. I just checked it to see if saving method sees actual values.