コード例 #1
0
        public static void WriteSetting(string key, string value, ConfigWriterSettings configWriterSettings)
        {
            XmlDocument doc = ConfigWriter.LoadConfigDocument(configWriterSettings.ConfigPath);
            // retrieve appSettings node
            XmlNode node = doc.SelectSingleNode(configWriterSettings.AppSettingsNode);

            if (node == null)
            {
                throw new InvalidOperationException("appSettings section not found in config file.");
            }

            try
            {
                // select the 'add' element that contains the key
                XmlElement elem = (XmlElement)node.SelectSingleNode(
                    string.Format(configWriterSettings.NodeForEdit, key));
                elem.FirstChild.InnerText = value;
                doc.Save(configWriterSettings.ConfigPath);
            }
            catch
            {
                throw;
            }
        }
コード例 #2
0
        public static void ChangeValueByKey(string key, string value, string attributeForChange, ConfigWriterSettings configWriterSettings)
        {
            XmlDocument doc = ConfigWriter.LoadConfigDocument(configWriterSettings.ConfigPath);
            // retrieve appSettings node
            XmlNode node = doc.SelectSingleNode(configWriterSettings.AppSettingsNode);

            if (node == null)
            {
                throw new InvalidOperationException("appSettings section not found in config file.");
            }

            try
            {
                // select the 'add' element that contains the key
                XmlElement elem = (XmlElement)node.SelectSingleNode(
                    string.Format(configWriterSettings.NodeForEdit, key));
                elem.SetAttribute(attributeForChange, value);
                doc.Save(configWriterSettings.ConfigPath);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }