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. I cant Save Appconfig key!!!

I cant Save Appconfig key!!!

Scheduled Pinned Locked Moved C#
workspace
3 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.
  • M Offline
    M Offline
    mrcooll
    wrote on last edited by
    #1

    hi all, when m modifying appconfig key it just doesnt save it //my code System.Configuration.Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None); if (config.AppSettings.Settings["T"] != null) { config.AppSettings.Settings["T"].Value = "False"; //config.AppSettings.Settings.Remove("DatabaseServer"); } else { config.AppSettings.Settings.Add("Key1", "False"); } config.Save(ConfigurationSaveMode.Full); ConfigurationManager.RefreshSection("appSettings"); why is that happening !!!

    realJSOPR M 2 Replies Last reply
    0
    • M mrcooll

      hi all, when m modifying appconfig key it just doesnt save it //my code System.Configuration.Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None); if (config.AppSettings.Settings["T"] != null) { config.AppSettings.Settings["T"].Value = "False"; //config.AppSettings.Settings.Remove("DatabaseServer"); } else { config.AppSettings.Settings.Add("Key1", "False"); } config.Save(ConfigurationSaveMode.Full); ConfigurationManager.RefreshSection("appSettings"); why is that happening !!!

      realJSOPR Offline
      realJSOPR Offline
      realJSOP
      wrote on last edited by
      #2

      Because you can't modify data in the app.config programatically. If you want user-specific data to be saved, you have to use the Settings object.

      "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997
      -----
      "...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001

      1 Reply Last reply
      0
      • M mrcooll

        hi all, when m modifying appconfig key it just doesnt save it //my code System.Configuration.Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None); if (config.AppSettings.Settings["T"] != null) { config.AppSettings.Settings["T"].Value = "False"; //config.AppSettings.Settings.Remove("DatabaseServer"); } else { config.AppSettings.Settings.Add("Key1", "False"); } config.Save(ConfigurationSaveMode.Full); ConfigurationManager.RefreshSection("appSettings"); why is that happening !!!

        M Offline
        M Offline
        Mark Salsbery
        wrote on last edited by
        #3

        Your code works for me. If you're looking for changes in your App.config, you're not going to find them there. The changes are in the actual runtime configuration file named yourappname.exe.Config, which will be in the same folder as the exe. Mark

        Mark Salsbery Microsoft MVP - Visual C++ :java:

        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