CSV to DataTabe C# all strings

this sln is for when u know / take all the columns as strings, but its very fast and simple.
thx to Alan here for the base:
public static DataTable TransferCSVToTable(string filePath)
   DataTable dt = new DataTable();
   string[] csvRows = System.IO.File.ReadAllLines(filePath);
   string[] fields = null;
   bool first = true;

   foreach (string csvRow in csvRows)
      fields = csvRow.Split(

      if (first)
   foreach (string header in fields)
         dt.Columns.Add(new DataColumn(header));
         first = false;
         DataRow row = dt.NewRow();
         row.ItemArray = fields;
   return dt;


Popular posts from this blog

c# Service Play Sound with NAudio example by Moshe

JS/JQ simulate Enter event

SOLVED The item could not be indexed successfully because the item failed in the indexing subsystem