5. 删除配置节
删除ConfigurationSectionGroup 
config.SectionGroups.Remove("group1");
//config.SectionGroups.Clear();
config.Save(ConfigurationSaveMode.Minimal);
删除ConfigurationSection 
config.Sections.Remove("add1");
//config.Sections.Clear();
if (config.SectionGroups["group1"] != null)
{
  config.SectionGroups["group1"].Sections.Remove("add2");
  //config.SectionGroups["group1"].Sections.Clear();
}
config.Save(ConfigurationSaveMode.Minimal);
6. 其他
可以使用 ConfigurationManager.OpenMachineConfiguration() 来操作 Machine.config 文件。
或者使用 System.Web.Configuration 名字空间中的 WebConfigurationManager 类来操作 ASP.net 配置文件。
ConfigurationManager还提供了AppSettings、ConnectionStrings、GetSection()等便捷操作。
7. 使用自定义类 
2006-4-17 补充,回复 ggy 网友的疑问。 
引用至 ggy
比如ConfigSectionData里面
除了简单类型之外,可不可以有自定义的类
 可以使用自定义类,不过需要定义一个转换器。
using System;
using System.Collections;
using System.Collections.Generic;
using System.Configuration;
using System.Globalization;
using System.ComponentModel;
// 要写入配置文件的自定义类
class CustomData
{
  public CustomData(string s)
  {
    this.s = s;
  }
  private string s;
  public string S
  {
    get { return s; }
    set { s = value; }
  }
}
// 自定义的转换器(演示代码省略了类型判断)
class CustomConvert : ConfigurationConverterBase
{
  public override bool CanConvertFrom(ITypeDescriptorContext ctx, Type type)
  {
    return (type == typeof(string));
  }
  public override object ConvertTo(ITypeDescriptorContext ctx, CultureInfo ci, object value, Type type)
  {
    return (value as CustomData).S;
  }
  public override object ConvertFrom(ITypeDescriptorContext ctx, CultureInfo ci, object data)
  {
    return new CustomData((string)data);;
  }
}
class ConfigSectionData : ConfigurationSection
{
  [ConfigurationProperty("id")]
  public int Id
  {
    get { return (int)this["id"]; }
    set { this["id"] = value; }
  }
  [ConfigurationProperty("time")]
  public DateTime Time
  {
    get { return (DateTime)this["time"]; }
    set { this["time"] = value; }
  }
  [ConfigurationProperty("custom")]
  [TypeConverter(typeof(CustomConvert))] // 指定转换器
  public CustomData Custom
  {
    get { return (CustomData)this["custom"]; }
    set { this["custom"] = value; }
  }
}
  
public class Program
{
  static void Main(string[] args)
  {
    Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
    ConfigSectionData data = new ConfigSectionData();
    data.Id = 1000;
    data.Time = DateTime.Now;
    data.Custom = new CustomData("abcdefg...");
    config.Sections.Add("add", data);
    config.Save(ConfigurationSaveMode.Minimal);
    // 读取测试
    ConfigSectionData configData = (ConfigSectionData)config.Sections["add"];
    Console.WriteLine(configData.Custom.S);
  }
}
保存后的配置文件 
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <configSections>
    <section name="add" type="..." />
  </configSections>
  <add id="1000" time="04/17/2006 22:06:58" custom="abcdefg..." />
</configuration>
更详细的信息可以看 MSDN 中关于 System.Configuration.ConfigurationConverterBase 的说明。
查看本文来源