This project is read-only.

ReadDataRecordAsStrings() unexpected behaviour

Mar 10, 2010 at 9:35 PM

Hi there,

Thanks for creating this very useful library, I am getting a lot of use out of it. But I am having one issue when using ReadDataRecordAsStrings() to read a CSV file that contains a header.

When opening a CSV file that was created in Excel I am experiencing an Index Out Of Bounds while looping through the array returned by ReadDataRecordAsStrings(). This is because the HeaderRecord for the file has X columns, but Excel in it's wisdom has only written X - 1 columns out for a certain row.

Am I wrong in expecting that ReadDataRecordAsStrings() to perform similarly to ReadDataRecord() by returning an array containing the same number of columns as the header? Or should I always be checking that ReadDataRecordAsStrings().Length == Header.Values.Count and handling this situation separately?

Thanks very much,




May 3, 2010 at 5:47 PM

Hi James,

KBCsv will only read whatever columns are in the row, regardless of any previous rows (including the header). If Excel is removing the last column(s) for rows that have no data in those columns, you will need to manually check for that.