Dim selxml As string=server.mappath("web.config")
try
ds.readxml(selxml)
ds.Tables(1).Rows(0)(1)=setname.text
ds.Tables(1).Rows(1)(1)=sethomepage.text
ds.Tables(1).Rows(2)(1)=seturl.text
ds.Tables(1).Rows(3)(1)=setemail.text
ds.Tables(1).Rows(5)(1)=setpage.text
ds.Tables(1).Rows(6)(1)=setlogo.text
ds.Tables(1).Rows(7)(1)="#"+setbgcolor.text
ds.Tables(1).Rows(8)(1)="#"+setlinebg.text
ds.Tables(1).Rows(9)(1)="#"+setline.text
ds.Tables(1).Rows(10)(1)="#"+setrebg.text
ds.Tables(1).Rows(11)(1)="#"+setlink.text
ds.Tables(1).Rows(12)(1)="#"+settext.text
ds.Tables(1).Rows(13)(1)="#"+setretext.text
ds.Tables(1).Rows(14)(1)=setadmin.text
ds.Tables(1).Rows(15)(1)=setpassword.text
ds.Tables(1).Rows(16)(1)=mailserver.text
ds.Tables(1).Rows(17)(1)=replymail.text
ds.Tables(1).Rows(18)(1)=ipinfo.SelectedItem.Value
ds.acceptchanges()
ds.writexml(selxml)
ds.clear()ds是DataSet对象。
try
ds.readxml(selxml)
ds.Tables(1).Rows(0)(1)=setname.text
ds.Tables(1).Rows(1)(1)=sethomepage.text
ds.Tables(1).Rows(2)(1)=seturl.text
ds.Tables(1).Rows(3)(1)=setemail.text
ds.Tables(1).Rows(5)(1)=setpage.text
ds.Tables(1).Rows(6)(1)=setlogo.text
ds.Tables(1).Rows(7)(1)="#"+setbgcolor.text
ds.Tables(1).Rows(8)(1)="#"+setlinebg.text
ds.Tables(1).Rows(9)(1)="#"+setline.text
ds.Tables(1).Rows(10)(1)="#"+setrebg.text
ds.Tables(1).Rows(11)(1)="#"+setlink.text
ds.Tables(1).Rows(12)(1)="#"+settext.text
ds.Tables(1).Rows(13)(1)="#"+setretext.text
ds.Tables(1).Rows(14)(1)=setadmin.text
ds.Tables(1).Rows(15)(1)=setpassword.text
ds.Tables(1).Rows(16)(1)=mailserver.text
ds.Tables(1).Rows(17)(1)=replymail.text
ds.Tables(1).Rows(18)(1)=ipinfo.SelectedItem.Value
ds.acceptchanges()
ds.writexml(selxml)
ds.clear()ds是DataSet对象。
{
string filename=this.MapPath(this.TemplateSourceDirectory) + @"\web.config";
XmlDocument xmldoc= new XmlDocument();
xmldoc.Load(filename); XmlNodeList topM=xmldoc.DocumentElement.ChildNodes;
IEnumerator it = topM.GetEnumerator();
while(it.MoveNext())
{
XmlElement element =(XmlElement)it.Current; if(element.Name.ToLower()=="appsettings")
{
XmlNodeList _node=element.ChildNodes;
if ( _node.Count >0 )
{
foreach(XmlElement el in _node)
{
if(el.Attributes["key"].InnerXml.Trim()==name)
{
el.Attributes["value"].Value=values;
}
}
}
}
}
xmldoc.Save(filename);
}
我的意思是往web.config里面写东西的!