Modifier les valeurs d'un fichier app.config d'une autre application avec XML

 01/01/2019 |   Admin |  C#


A utiliser SEULEMENT pour ce cas, sinon utiliser les méthodes habituelles avec configuration manager.
private static string UpdateValueAppConfig(string node, string newValue, string path)
{
try
{
var element = XElement.Load(path + "/app.config");
element.XPathSelectElement("//add[@key='" + node + "']").Attribute("value").Value = newValue;
element.Save(path + "/app.config");
}
catch (Exception ex)
{
        return "<p style=\"color:red\">Error to change app.config with this value " + newValue + ", this node " + node + " and this path " + path + "<br/> " + ex.Message + "</p>";
}
}

Lire >>

  • 1