Updating XML config files I have been unable to find any other way to update a user config file than the following method. 

public class SettingServices : ISettingServices
{
    public UserSetting GetUserSetting()
    {
        XmlSerializer reader = new XmlSerializer(typeof(UserSetting));
        StreamReader file = new StreamReader(UserConfig);
        UserSetting settings = new UserSetting();
        settings = (UserSetting)reader.Deserialize(file);
        return settings;
    }
    public void CreateUserSetting(UserSetting userSetting)
    {
        XmlSerializer writer = new XmlSerializer(typeof(UserSetting));
        StreamWriter file = new StreamWriter(UserConfig);
        writer.Serialize(file, userSetting);
        file.Close();
    }
    public void UpdateUserSetting(UserSetting userSetting)
    {
        UserSetting currentSettings = GetUserSetting();
        UserSetting newSetting = new UserSetting();
        newSetting.Name = (userSetting.Name == null) ? currentSettings.Name : userSetting.Name;
        newSetting.ViewChangeLog = (userSetting.ViewChangeLog == null) ? currentSettings.ViewChangeLog : userSetting.ViewChangeLog;
        newSetting.PrimaryRowColor = (userSetting.PrimaryRowColor == null) ? currentSettings.PrimaryRowColor : userSetting.PrimaryRowColor;
        newSetting.SecondaryRowColor = (userSetting.SecondaryRowColor == null) ? currentSettings.SecondaryRowColor : userSetting.SecondaryRowColor;
        newSetting.Font = (userSetting.Font == null) ? currentSettings.Font : userSetting.Font;
        CreateUserSetting(newSetting);
    }
    private static string UserConfig
    {
        get
        {
            string configDirectory = new Uri(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\CVS\\ICMQuery").LocalPath;
            return new Uri(configDirectory + "\\" + System.Environment.UserName + ".config").LocalPath;
        }
    }
}


Can someone please show me the light. I would preferably like to be able to update singular elements within the UserSetting class without destroying and rewriting the file every time I have to update it.
Preferably I'd like to just be able to update that node in the XML file without having to rewrite the whole file every time a change is made.


In general, that's simply not possible, because XML is a text-based format.

Imagine you have the following file:



&lt;UserSettings&gt;
    &lt;Name&gt;Aron&lt;/Name&gt;
    &lt;!-- other settings here --&gt;
&lt;/UserSettings&gt;


Now you want to fix the name from “Aron” to “Aaron”:

&lt;UserSettings&gt;
    &lt;Name&gt;Aaron&lt;/Name&gt;
    &lt;!-- other settings here --&gt;
&lt;/UserSettings&gt;


But doing this means that everything that's after the Name line has to be moved by one byte in the file, so almost the whole file has to be rewritten.

With config files, this usually doesn't matter, because they tend to be relatively small. If it does matter to you, you will have to use another way of saving the config; a good choice might be an embedded database, like SQL Server Compact or SQLite.

Yet another option would be to use .settings files (built-in in VS). It doesn't save you from rewriting the file, but it saves you from having to write all that code.