Convert CSV to XML

This is used to convert csv to xml

private void ConverCSVToXml()
{
TextReader file = File.OpenText(“invoices.txt”);
DataTable table = new DataTable(“invoice”);

string line = file.ReadLine();
foreach (string s in line.Split(‘\t’))
table.Columns.Add(s);

line = file.ReadLine();
while (line != null)
{
table.Rows.Add(line.Split(‘\t’));
line = file.ReadLine();
}

file.Close();
table.WriteXml(“invoices.xml”);
}

Author: Deepak Rao

Advertisement

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.