c# – How update xml file settings – Education Career Blog

I have my own xml settings file in winform app. It is installed on some location. And I need to update this file (add some new atributes/settings) without loosing old settings.

Example old xml setting:

  <someSetting>Old Value</someSetting>

Example new xml setting file:

   <someSetting>default value</someSettingNew>
   <someSettingNew>defaul value</someSettingNew>

I need new xml setting file look after update like this:

   <someSetting>Old Value</someSettingNew>
   <someSettingNew>defaul value</someSettingNew>

How can I do this in C# .NET Framework 3.5. And I know that I can do this with App.config, but I need my own manager. I need to share this config file between two apps (Settings App for Windows Service and that Windows Service)


I have to explain my workflow:

  1. windows service + app gui is instaled with instalator
  2. windows service is configured with app gui
  3. i will create update (dll + new xml config file)
  4. dll’s are deployed, and i need to merge old xml config file with new config file (new parameters and default value). How do this programmicaly? I want update only xml file, not program code. In windows servic app I can detect update so I can call some procedure to load new settings. Thats what I need, how do this procedure?


You could use XDocument:

var doc = XDocument.Load("test.xml");
doc.Root.Add(new XElement("someSettingNew", "defaul value"));

Leave a Comment