The following code reads the CSV file to an array. LINQ is used to loop through
the array and the contents are written as XML using XElement (System.XML.Linq).
public void ConvertCSVToXML()
{
String[] FileContent = System.IO.File.ReadAllLines(@"C:\Temp\vba.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])
)
);
System.IO.File.WriteAllText(@"C:\Temp\vba.xml", XMLNS + Inv.ToString());
}