static void UpdateAppConfig() { Dictionary <string, string> dic = new Dictionary <string, string>(); dic["AccountName"] = "mediavaletdevasia12"; string appConfigFile = @"C:\webjob\MediaValet.WebJobs.EntityChangeListener.exe.config"; System.Xml.Linq.XElement xelement = System.Xml.Linq.XElement.Load(appConfigFile); IEnumerable <System.Xml.Linq.XElement> elements = xelement.Elements().ToList(); // Read the entire XML foreach (var element in elements) { if (element.Name.LocalName == "appSettings") { var eles = element.Elements().ToList(); foreach (var ele in eles) { if (dic.ContainsKey(ele.Attribute("key").Value)) { ele.Attribute("value").Value = dic[ele.Attribute("key").Value]; } } } } var ww = new System.Xml.XmlTextWriter(appConfigFile, System.Text.Encoding.UTF8); ww.Formatting = System.Xml.Formatting.Indented; ww.WriteStartDocument(); xelement.WriteTo(ww); ww.Flush(); ww.Close(); }