读写xml节点读:
    //打开某文件(假设web.config在根目录中)
    string filename=Server.MapPath("/") + @"WebApplication1\web.config";
    XmlDocument xmldoc= new XmlDocument();
    xmldoc.Load(filename);
 
    //得到顶层节点列表
    XmlNodeList topM=xmldoc.DocumentElement.ChildNodes;
    foreach(XmlElement element in topM)
    {
     if(element.Name.ToLower()=="appsettings")
     {
 
      //得到该节点的子节点
      XmlNodeList nodelist=element.ChildNodes;
 
      if ( nodelist.Count >0 )
      {
       //DropDownList1.Items.Clear();
 
       foreach(XmlElement el in nodelist)//读元素值
       {
        //DropDownList1.Items.Add(el.Attributes["key"].InnerXml);
        //this.TextBox2.Text=el.Attributes["key"].InnerText;
        this.TextBox2.Text=el.Attributes["key"].Value;
        this.Label1.Text=el.Attributes["value"].Value;
 
 
            //同样在这里可以修改元素值,在后面save。
         //  el.Attributes["value"].Value=this.TextBox2.Text;
       }
       }     }    }    xmldoc.Save(filename);

解决方案 »

  1.   

    其实,也就是读文本文件,下面代码仅供参考
    1.  读文件 //方法1        StreamReader srFile=new StreamReader(filename,Encoding.Default);        while(srFile.Peek() > -1) // Check EOF        {            sql+= srFile.ReadLine(); // Read one line        }        srFile.Close();        this.richTextBox1.Text=sql;  //方法2        StreamReader sr=File.OpenText(filename);        String input;        while((input=sr.ReadLine())!=null)        {            sql+=input;        }        sr.Close();        this.richTextBox1.Text=sql;  //方法3        this.richTextBox1.LoadFile(filename,RichTextBoxStreamType.PlainText);