从安装程序访问配置文件中的“applicationSettings”部分(不是“appSettings”)

我正在为我们构建的Web应用程序创建设置。 不,我有一个配置文件,看起来像这样,包含一个’appSettings’部分和一个’applicationSettings’部分:

              Username   Servername   Database   Password     

现在,从我的设置我必须使用Configuration config = WebConfigurationManager.OpenWebConfiguration(“/”+ targetvdir)从文件系统打开配置文件; 变量’targetvdir’包含配置文件的路径。

我得到了配置文件,我可以编辑’appSettings’部分

 config.AppSettings.Settings["Password"].Value = "something"; 

但是无论如何我都无法使用’applicationSettings’部分。 在Web应用程序本身中,我访问该部分

 Properties.Settings.Default. 

但是这不适用于我的安装项目。

有没有机会像’appSettings’部分一样轻松编辑’applicationSettings’部分? 或者我是否必须编辑xml本身? 任何提示都非常感谢。

亲切的问候,凯哈特曼

我为自己回答我的问题而道歉,因为我在发布后立即找到了解决方案。 这个问题基本上给出了答案: 在运行时保存并重新加载app.config(applicationSettings)

我不得不使用这段代码,写入’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();