<configuration>
<appSettings>
<!--   User application and configured property settings go here.-->
<!--   Example: <add key="settingName" value="settingValue"/> -->
<add key="howmanymups" value="3" />
                  <add key="mup0" value="first" />
</appSettings>
</configuration>
即可

解决方案 »

  1.   

    我的意思是如何在程序中將如下一行加到config文件里去,而不是手工編輯.
        <add key="mup0" value="first" />
      

  2.   

    //得到顶层节点列表
    XmlNodeList topM=xmldoc.DocumentElement.ChildNodes;
    foreach(XmlElement element in topM)
    {
    if(element.Name.ToLower()=="appsettings")
    { XmlElement elem =xmldoc.CreateElement("add");
    element.AppendChild(elem);
    XmlAttribute xa=xmldoc.CreateAttribute("key");
    xa.Value="mup0"; XmlAttribute xa2=xmldoc.CreateAttribute("value");
    xa2.Value="first"; elem.SetAttributeNode(xa);
    elem.SetAttributeNode(xa2);
    xmldoc.Save(filename);

    }
    }
      

  3.   


    这里的xmldoc,是一个xml文件对象
    //打开某文件(假设WEB。CONFIG在根目录中)
    string filename=Server.MapPath("/") + @"WebApplication1\web.config";
    XmlDocument xmldoc= new XmlDocument();
    xmldoc.Load(filename);
      

  4.   

    其实就是对XML文件的操作,你看看C#对XML文件操作就OK了