Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. 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 using .NET (C#) Visual Studio2005

Scheduled Pinned Locked Moved C#
csharpxmlwcftutorialquestion
4 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    Thomas_Mathews
    wrote on last edited by
    #1

    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>

    M N T 3 Replies Last reply
    0
    • T Thomas_Mathews

      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>

      M Offline
      M Offline
      Manas Bhardwaj
      wrote on last edited by
      #2

      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.

      1 Reply Last reply
      0
      • T Thomas_Mathews

        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>

        N Offline
        N Offline
        Najmal
        wrote on last edited by
        #3

        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

        1 Reply Last reply
        0
        • T Thomas_Mathews

          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>

          T Offline
          T Offline
          Thomas_Mathews
          wrote on last edited by
          #4

          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 :)

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups