We read a tab delimited file into a DataTable
with the following code.
//read the uploaded file...
var records = File.ReadAllLines(Server.MapPath("~/UploadFiles/") + Session.SessionID + "/orderEDI.txt").ToList();
//load the data into the temporary table...
records.ForEach(record => loadTable.Rows.Add(record.Split((char)9)));
This works just fine providing there are not more tabs in the file than there are columns in the DataTable.
I'm looking to find out if there's a way I can limit the number of columns it reads from the file. Or any other suggestions around this issue. It must read an absolute minimum of 10 columns (and ideally, only 10)
I build the DataTable
and add columns to it before this load occurs. Would it be better to not add columns and just load the file into the DataTable
and then read the table by column index rather than name?
Really not sure which way to go and would appreciate some experienced opinions.
Thanks