C# Program to read TAB Seperated CSV File Header and Data Rows

Posted by Rajnilari2015 under C# category on | Points: 40 | Views : 213
public System.Data.DataTable GetDataTable(string strFileName)

var dt = new DataTable();
var lineFields = File.ReadAllLines(strFileName).Select(line => line.Split('|'));
dt.Columns.AddRange(lineFields.First().Select(i => new DataColumn(i)).ToArray()); //add header
lineFields.Skip(1).ToList().ForEach(i => dt.Rows.Add(i)); //add data rows

return dt;

Comments or Responses

Login to post response