Skip to content

Instantly share code, notes, and snippets.

@angelovstanton
Created July 15, 2015 20:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save angelovstanton/301debdc0827ce507030 to your computer and use it in GitHub Desktop.
Save angelovstanton/301debdc0827ce507030 to your computer and use it in GitHub Desktop.
string appConfigFilePath = string.Concat(Assembly.GetExecutingAssembly().Location, ".config");
ConfigModificatorSettings appConfigWriterSettings =
new ConfigModificatorSettings("//appSettings", "//add[@key='{0}']", appConfigFilePath);
string value = ConfigurationManager.AppSettings["testKey1"];
System.Console.WriteLine("Value before modification: {0}", value);
ConfigModificator.ChangeValueByKey(
key: "testKey1",
value: "ChangedValueByModificator",
attributeForChange: "value",
configWriterSettings: appConfigWriterSettings);
ConfigModificator.RefreshAppSettings();
value = ConfigurationManager.AppSettings["testKey1"];
System.Console.WriteLine("Value after modification: {0}", value);
//Example how to change Custom XML configuration
string carsConfigFilePath = "Cars.xml";
ConfigModificatorSettings carsConfigWriterSettings =
new ConfigModificatorSettings("//cars", "//car[@name='{0}']", carsConfigFilePath);
ConfigModificator.ChangeValueByKey(
key: "BMW",
value: "Mazda",
attributeForChange: "name",
configWriterSettings: carsConfigWriterSettings);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment