Access section 'applicationSettings' (not 'appSettings') in config file from setup

孤人 提交于 2019-12-06 14:13:50
Kai Hartmann

I apologize for answering my question by myself, since I found the solution right after posting it. This question gave the answer basically: Save and reload app.config(applicationSettings) at runtime

I had to use this code, to write to that section 'applicationSettings':

// this gets the applicationSettings section (and the inner section 'inoBIBooks.My.MySettings')
Configuration config = WebConfigurationManager.OpenWebConfiguration("/" + targetvdir);
ConfigurationSectionGroup applicationSectionGroup = config.GetSectionGroup("applicationSettings");
ConfigurationSection applicationConfigSection = applicationSectionGroup.Sections["inoBIBooks.My.MySettings"];
ClientSettingsSection clientSection = (ClientSettingsSection)applicationConfigSection;

// set a value to that specific property
SettingElement applicationSetting = clientSection.Settings.Get("BIDB_Username");
applicationSetting.Value.ValueXml.InnerText = "username";

// without this, saving won't work
applicationConfigSection.SectionInformation.ForceSave = true;
// save
config.Save();
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!