How to Convert CSV to XML using C#

public void ConvertCSVToXML()

{

String[] FileContent = File.ReadAllLines(@"C:\Temp\pan.csv");

String XMLNS = "";

XElement Inv = new XElement("Invoice",

from items in FileContent

let fields = items.Split(',')

select new XElement("Item",

new XElement("ID", fields[0]),

new XElement("Name", fields[1]),

new XElement("Price", fields[2]),

new XElement("Availability", fields[3]),

new XElement("TotalPrice", fields[4])

)

);

File.WriteAllText(@"C:\Temp\pan.xml", XMLNS + Inv.ToString() );

}

No comments:

Post a Comment