.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Gaurav Pal

Home >> Code Snippets >> File Operation >> Post New Resource Bookmark and Share   

 Subscribe to Code Snippets

How to read XML file and write it to any file formates [eg: txt,xml,doc,docx,html]?

Posted By:Pravin       Posted Date: August 05, 2011    Points: 40    Category: File Operation    URL: http://www.dotnetspark.com  

Here i have attached the sample code that will read the XML file and create a new directory to save the new written file in different file format.

using System.IO;
using System.Xml;
using System.Xml.Schema;

private void XmlFileReadWriter()

        string sfilename = @"D:\ABC\Sample.xml";
         //Create the DataSet to read the schema into.
            DataSet thisDataSet = new DataSet();

         // Create a FileStream object with the file path and name.
            FileStream myFileStream = new FileStream (sfilename,FileMode.Open);

         // Create a new XmlTextReader object with the FileStream.
           XmlTextReader myXmlTextReader = new XmlTextReader(myFileStream);

         // Read the schema into the DataSet and close the reader.

            if (thisDataSet == null) { return; }
         // Create a file name with extension to write to.
            string filename = @"D:\Newfolder\ABC.txt";
         // Create the FileStream to write with.
            FileStream myFileStream1 = new FileStream
         // Create an XmlTextWriter with the fileStream.
            XmlTextWriter myXmlWriter =
            new XmlTextWriter(myFileStream1, System.Text.Encoding.Unicode);
         // Write to the file with the WriteXml method.


Further Readings:


No response found. Be the first to respond this post

Post Comment

You must Sign In To post reply
Find More code samples in C#, ASP.Net, Vb.Net and more Here

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend