If you are using , an applicaiton.exe.config then you can use something code similar to this .
In below code example - you have to make changes accordingly
ArrayList keysArrList = new ArrayList();
keysArrList.AddRange(hashConfigTable.Keys);
keysArrList.Sort();
//Get the application configuration file.
System.Configuration.Configuration config =
ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
if (filepath.Length > 0)
{
System.Configuration.ExeConfigurationFileMap configFileMap = new ExeConfigurationFileMap();
configFileMap.ExeConfigFilename = filepath;
config = ConfigurationManager.OpenMappedExeConfiguration(configFileMap, ConfigurationUserLevel.None);
}
ConfigurationSectionGroup mySectiongrp = config.GetSectionGroup("IF ANY GROUP PRESENT IN CONFIG FILE");
ConfigurationSection mySection = mySectiongrp.Sections[sFormatClassName];
foreach (Object okey in keysArrList)
{
XmlNode node = GetNodeAvailable(document, okey.ToString());
XmlAttributeCollection attrcoll = node.Attributes;
foreach (XmlAttribute attr in attrcoll)
{
if ( String.Equals(attr.Name ,"VALUE",StringComparison.OrdinalIgnoreCase))
{
XmlComment newComment;
newComment = document.CreateComment(string.Format(" Modified by Batch WinConsole Version:{0} on Date:{1} PREVIOUS_VALUE:{2} By:{3}", m_sFileVersion, DateTime.Now, attr.Value,System.Environment.UserName));
XmlElement element = attr.OwnerElement;
element.AppendChild(newComment);
attr.Value = Convert.ToString(hashConfigTable[okey]);
}
}
}
mySection.SectionInformation.SetRawXml(document.OuterXml);
//Before save take a backup
FileSystemUtil fsutil = new FileSystemUtil();
string sNewfilename=string.Format("{0}_{1}.config",Path.GetFileNameWithoutExtension(filepath), DateTime.Now.ToString("yyyyMMMdd_hhmmss"));
fsutil.FileCopy(filepath, Path.Combine(Path.GetDirectoryName(filepath), "Backup", "config", sNewfilename));
//final Save
config.Save(ConfigurationSaveMode.Full);
ConfigurationManager.RefreshSection(sFormatClassName);