对。
如果允许应用程序更改应用程序文件夹中的文件-更新
*.config
update
/
save
/
refresh
示例:假设您存储了wcf部分的组(
<bindings>
,
<behaviors>
.. 等)在文件中
wcfsections.test.config
Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
ConfigurationSectionCollection sections = ServiceModelSectionGroup.GetSectionGroup(config).Sections;
sections.Clear();
string fileName = ((GeneralSettings)ConfigurationManager.GetSection("generalSettings")).AppConfigServiceModelSectionFile;
XDocument doc = XDocument.Load(fileName);
var xmlGroup = (from x in doc.Descendants("system.serviceModel") select x).FirstOrDefault();
string[] sectionsInUpdateOrder = { "bindings", "comContracts", "behaviors", "extensions", "services", "serviceHostingEnvironment", "client", "diagnostics" };
foreach (string key in sectionsInUpdateOrder)
{
var e = (from x in xmlGroup.Elements(key) select x).FirstOrDefault();
if (e != null)
{
ConfigurationSection currentSection = sections[e.Name.LocalName];
string xml = e.ToString();
currentSection.SectionInformation.SetRawXml(xml);
}
}
config.Save();
foreach (string key in sectionsInUpdateOrder)
ConfigurationManager.RefreshSection("system.serviceModel/" + key);