How to use ConfigurationManager to modifying "applicationSettings" section of App.config using .NET (C#) Visual Studio2005
-
How to use ConfigurationManager to modifying "applicationSettings" section of App.config? Or it there any other way to do same? I have the code to modify "appSettings" section of app.config. 1) To modify key "SApp.Properties.Settings" of "appSettings" section of app.config I used below code:: ExeConfigurationFileMap fileMap = new ExeConfigurationFileMap(); fileMap.ExeConfigFilename = @"D:\app.config"; Configuration config = ConfigurationManager.OpenMappedExeConfiguration(fileMap, ConfigurationUserLevel.None); AppSettingsSection section = (AppSettingsSection)config.GetSection("appSettings"); section.Settings["SApp.Properties.Settings"].Value = "i23"; config.Save(); 2)My App.config has below content:: <?xml version="1.0" encoding="utf-8"?> <appSettings> <add key="SApp.Properties.Settings" value="http://2344/soap/services"/> </appSettings> <applicationSettings> <Generate.Properties.Settings> <setting name="Generate_GeneratePDFServiceService" serializeAs="String"> <value>http://2435/GeneratePDFService</value> </setting> </Generate.Properties.Settings> </applicationSettings>
-
How to use ConfigurationManager to modifying "applicationSettings" section of App.config? Or it there any other way to do same? I have the code to modify "appSettings" section of app.config. 1) To modify key "SApp.Properties.Settings" of "appSettings" section of app.config I used below code:: ExeConfigurationFileMap fileMap = new ExeConfigurationFileMap(); fileMap.ExeConfigFilename = @"D:\app.config"; Configuration config = ConfigurationManager.OpenMappedExeConfiguration(fileMap, ConfigurationUserLevel.None); AppSettingsSection section = (AppSettingsSection)config.GetSection("appSettings"); section.Settings["SApp.Properties.Settings"].Value = "i23"; config.Save(); 2)My App.config has below content:: <?xml version="1.0" encoding="utf-8"?> <appSettings> <add key="SApp.Properties.Settings" value="http://2344/soap/services"/> </appSettings> <applicationSettings> <Generate.Properties.Settings> <setting name="Generate_GeneratePDFServiceService" serializeAs="String"> <value>http://2435/GeneratePDFService</value> </setting> </Generate.Properties.Settings> </applicationSettings>
Thomas_Mathews wrote:
How to use ConfigurationManager to modifying "applicationSettings" section of App.config
No, you can not. ConfigurationManager does not have an interface to do that. And the reason is based on design principles. Though, you can use the code to modify the App.config considering it to be a xml file. I would suggest you to store the settings which may be changed using the application in some other Xml file/database.
Please remember to rate helpful or unhelpful answers, it lets us and people reading the forums know if our answers are any good.
-
How to use ConfigurationManager to modifying "applicationSettings" section of App.config? Or it there any other way to do same? I have the code to modify "appSettings" section of app.config. 1) To modify key "SApp.Properties.Settings" of "appSettings" section of app.config I used below code:: ExeConfigurationFileMap fileMap = new ExeConfigurationFileMap(); fileMap.ExeConfigFilename = @"D:\app.config"; Configuration config = ConfigurationManager.OpenMappedExeConfiguration(fileMap, ConfigurationUserLevel.None); AppSettingsSection section = (AppSettingsSection)config.GetSection("appSettings"); section.Settings["SApp.Properties.Settings"].Value = "i23"; config.Save(); 2)My App.config has below content:: <?xml version="1.0" encoding="utf-8"?> <appSettings> <add key="SApp.Properties.Settings" value="http://2344/soap/services"/> </appSettings> <applicationSettings> <Generate.Properties.Settings> <setting name="Generate_GeneratePDFServiceService" serializeAs="String"> <value>http://2435/GeneratePDFService</value> </setting> </Generate.Properties.Settings> </applicationSettings>
Hi....... U can use ConfigurationManager to modifying "applicationSettings" and also can do the same by concidering it as a XML file... Just follow below Link to know more... About ConfigurationManager
-
How to use ConfigurationManager to modifying "applicationSettings" section of App.config? Or it there any other way to do same? I have the code to modify "appSettings" section of app.config. 1) To modify key "SApp.Properties.Settings" of "appSettings" section of app.config I used below code:: ExeConfigurationFileMap fileMap = new ExeConfigurationFileMap(); fileMap.ExeConfigFilename = @"D:\app.config"; Configuration config = ConfigurationManager.OpenMappedExeConfiguration(fileMap, ConfigurationUserLevel.None); AppSettingsSection section = (AppSettingsSection)config.GetSection("appSettings"); section.Settings["SApp.Properties.Settings"].Value = "i23"; config.Save(); 2)My App.config has below content:: <?xml version="1.0" encoding="utf-8"?> <appSettings> <add key="SApp.Properties.Settings" value="http://2344/soap/services"/> </appSettings> <applicationSettings> <Generate.Properties.Settings> <setting name="Generate_GeneratePDFServiceService" serializeAs="String"> <value>http://2435/GeneratePDFService</value> </setting> </Generate.Properties.Settings> </applicationSettings>
Hi All, You can modify value of 'AppSettingsSection' by below code. ConfigurationSectionGroup sectionGroup = config.SectionGroups["applicationSettings"]; ClientSettingsSection section = (ClientSettingsSection)sectionGroup.Sections["....Settings"]; section.Settings.Get("GeneratePDF...").Value.ValueXml.InnerText = urlname; config.Save(ConfigurationSaveMode.Minimal, true); -Thomas :)