Search code examples
c#csvfilehelpers

FileHelpers -- Only read Nth Columns


I am using FileHelpers to read a CSV file that have hundreds of columns but I only need the first twenty or so, so while creating the mappings in the class I only put those twenty columns.

When do the parsing, I get the following exception

Delimiter ',' found after the last field 'CompanyDivision' (the file is wrong or you need to add a field to the record class)

I read in other answers that a hack for this is to put dummy fields for the rest of the columns you don't want to read but, as I said, I have hundreds of those.

Is there a way to configure the engine to stop after a certain number of columns? or is there a way to extend or modify the engine to do this?


Solution

  • You can try adding an array dummy field:

    private string[] mDummyField;
    

    With that the rest of the fields will be in that field. You must use the last version of the library.