DataSet ds = new DataSet();
FileStream fs = new FileStream(Server.MapPath("users.xml"),
FileMode.Open,FileAccess.Read);
StreamReader reader = new StreamReader(fs);
ds.ReadXml(reader);
fs.Close();

解决方案 »

  1.   

    上面的代码读入包含已验证用户名和密码组合的 XML 文件。所检索的数据驻留在 ds。
      

  2.   

    以下示例创建一个 System.IO.FileStream 对象。然后用 WriteXml 方法将该对象写入 XML 文档。
    private void WriteXmlToFile(DataSet thisDataSet) {
       if (thisDataSet == null) { return; }
       // Create a file name to write to.
       string filename = "myXmlDoc.xml";
       // Create the FileStream to write with.
       System.IO.FileStream myFileStream = new System.IO.FileStream
          (filename, System.IO.FileMode.Create);
       // Write to the file with the WriteXml method.
       thisDataSet.WriteXml(myFileStream);   
      

  3.   

    既然是XML文件,为什么不用System.Xml.XmlTextWriter和System.Xml.XmlTextReader,很方便。