Friday, 8 October 2010

C#.net Read & Write XML Files

Code to Read an XML File into a DataSet;

this.workingDataSet = new DataSet();
FileStream xmlStream = new FileStream(fileName, FileMode.Open, FileAccess.Read);
workingDataSet.ReadXml(xmlStream);
xmlStream.Close();

Code to Write a DataSet to an XML file (UTF8);

FileStream xmlStream = new FileStream(fileName, FileMode.Create, FileAccess.Write);
XmlTextWriter xmlWriter = new XmlTextWriter(xmlStream, Encoding.UTF8);
workingDataSet.WriteXml(xmlWriter);
xmlStream.Close();

No comments:

Post a Comment

Thanks for the feedback!