Modify AppSetting Value in config file

Ndebata
Posted by Ndebata under Windows Forms category on | Points: 40 | Views : 1823
var configname = Assembly.GetEntryAssembly().ManifestModule.Name+".config";
if (File.Exists(configname))
{
XElement xe = XElement.Load(configname);
var el = xe.Element("appSettings");
if (el != null)
{
var _mk = el.Elements().FirstOrDefault(a => a.Attribute("key").Value == "KeyName");
if (_mk != null)
{
if (_mk.Attribute("value") != null)
{
_mk.Attribute("value").Value = "New Value";
xe.Save(configname);
}
}
}
}

Comments or Responses

Login to post response