Click here to Skip to main content
15,905,508 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
here my requirement is
first it should read data from the text file and then write data into xml file

1 solution

Really, that is going to depend on wht you have in your file, and what you want to do with it. But...
string text = File.ReadAllText(@"D:\Temp\myFile.txt");
XmlDocument doc = new XmlDocument();
XmlDeclaration dec = doc.CreateXmlDeclaration("1.0", null, null);
XmlElement root = doc.CreateElement("MyRoot");
XmlElement elem = doc.CreateElement("MyElement");
elem.SetAttribute("MyData", text);
File.WriteAllText(@"D:\Temp\myFile.xml", doc.OuterXml);
Share this answer
RaisKazi 18-Nov-11 13:51pm    
5ed. Op's requirement makes sense provided text file also contains XML Data. :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900