Created
July 15, 2015 20:06
-
-
Save angelovstanton/5e018a5b850a578cb710 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static void ChangeValueByKey(string key, string value, string attributeForChange, ConfigModificatorSettings configWriterSettings) | |
{ | |
XmlDocument doc = ConfigModificator.LoadConfigDocument(configWriterSettings.ConfigPath); | |
XmlNode rootNode = doc.SelectSingleNode(configWriterSettings.RootNode); | |
if (rootNode == null) | |
{ | |
throw new InvalidOperationException("the root node section not found in config file."); | |
} | |
try | |
{ | |
XmlElement elem = (XmlElement)rootNode.SelectSingleNode(string.Format(configWriterSettings.NodeForEdit, key)); | |
elem.SetAttribute(attributeForChange, value); | |
doc.Save(configWriterSettings.ConfigPath); | |
} | |
catch (Exception ex) | |
{ | |
throw ex; | |
} | |
} | |
private static XmlDocument LoadConfigDocument(string configFilePath) | |
{ | |
XmlDocument doc = null; | |
try | |
{ | |
doc = new XmlDocument(); | |
doc.Load(configFilePath); | |
return doc; | |
} | |
catch (System.IO.FileNotFoundException e) | |
{ | |
throw new Exception("No configuration file found.", e); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment