0

I have the following code to change key value in Web.config file.

Configuration webConfigApp = WebConfigurationManager.OpenWebConfiguration("~");
webConfigApp.AppSettings.Settings["Email"].Value = "abc@def.com";
webConfigApp.Save();

It changes the value successfully but it also affects the file structure. I have some comments in the file that comments are gone after running the above code.

Is there any code which only updates the key value and not affects the entire file?

V.Mulik
  • 119
  • 1
  • 4
  • 17

1 Answers1

0

There is an overload on Save method that is

Save(ConfigurationSaveMode)

If you set it to Minimal it will save only the changed properties. Please take a look at https://learn.microsoft.com/en-us/dotnet/api/system.configuration.configurationsavemode?view=netframework-4.8

CyberZeus
  • 211
  • 1
  • 5