<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>
即可
<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>
即可
<add key="mup0" value="first" />
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);
}
}
这里的xmldoc,是一个xml文件对象
//打开某文件(假设WEB。CONFIG在根目录中)
string filename=Server.MapPath("/") + @"WebApplication1\web.config";
XmlDocument xmldoc= new XmlDocument();
xmldoc.Load(filename);