System.configuration.ConfigurationSettingS.GetConfig ("ApplicationConfiguration"); orruntime web.config / app.config editing http://www.eggheadcafe.com/articles/20030907.asp ------------- -------------------------------------------------- ---------------
using System; using System.Xml; using System.Configuration; using System.Collections; using System.Reflection; using System.Diagnostics; public enum ConfigFileType {WebConfig, AppConfig} public class AppConfig: System.Configuration.AppSettingsReader {public string docName = String.Empty; private XmlNode node = null; private int _configType; public int configType {get {return _configType;} set {_configType = value;}} public bool SetValue (string key, string value) {XmlDocument cfgDoc = new XmlDocument () ; loadConfigDoc (cfgDoc); // retrieve the appSettings node node = cfgDoc.SelectSingleNode ( "// appSettings"); if (node == null) {throw new System.InvalidOperationException ( "appSettings section not found");} try { // xpath select setting "add" Element That Contains this key xmlelement addelem = (xmlelement) node.selectsinglenode ("// add [@ Key = '" key "); if (addelem! = Null) { Addelem.SetaTRibute ("Value", Value);} // Not found, so we need to add the element, key and value else { XmlElement entry = cfgDoc.CreateElement ( "add"); entry.SetAttribute ( "key", key); entry.SetAttribute ( "value", value); node.AppendChild (entry);} // save it saveConfigDoc (cfgDoc, docName); return true;} catch {return false;}} private void saveConfigDoc (XmlDocument cfgDoc, string cfgDocPath) {try {XmlTextWriter writer = new XmlTextWriter (cfgDocPath, null); writer.Formatting = Formatting.Indented; cfgDoc.WriteTo ( Writer); Writer.Flush (); Writer.close (); return;} catch {throw;}} public bool removelelement (String elementkey) {Try {xmlDocument cfgdoc = new xmlDocument ();