0

I have huge CSV file (1GB) which looks like that:

1140|2017|0213065852|2001|99|Ä‚/ŮŌçlš˝Ă_Âá'ÄǸ|-3858,18|4015,36|100,17|19,34|0,00|0,00|0,00|40,00|0,00|0,00|0,00|32,57|0,00|0,00|0,00|0,00|0,00|0,00|0,00|0,00|0,00|12|12|74|18|24620,65|11903,96|29385,35|10993,94|0,00|-2520,88|0|0100|301|02|0302|N|N|N| | |2001-12-27 00:00:00|N|1140|1313|BG4CSXF0|        |2002-01-01 00:28:13| |0,00|0,00|0,00|0,00|0,00|0,00|0,00|0,00|0,00|0,00|0,00
1140|2017|0213065852|2002|99|ľë¸Â‰_gÂýľ)Ľ¸ů_°Ë
…p'™m'î'Ä_|-3799,76|3982,22|461,66|1,48|0,00|0,00|0,00|0,00|0,00|0,00|0,00|100,23|0,00|0,00|0,00|0,00|0,00|0,00|0,00|0,00|0,00|27|43|189|20|40140,74|48835,00|69605,32|19312,00|0,00|-3427,87|0|0100|301|02|0303|N|N|N| | |2002-12-27 00:00:00|N|1140|1313|BG4CSXF0|        |2003-01-01 01:35:56| |0,00|0,00|0,00|0,00|0,00|0,00|0,00|0,00|0,00|0,00|0,00

When I try to read this file using FileHelpers using following code:

FileHelperEngine engine = new FileHelperEngine(typeof(BGDTMDF));
BGDTMDF[] tab = (BGDTMDF[])engine.ReadFile(path);

I get an error:

The delimiter '|' can´t be found after the field 'MDF_SALDOS_MEDIOS' at line 2 (the record has less fields, the delimiter is wrong or the next field must be marked as optional).

My class looks like:

[DelimitedRecord("|")]
public class BGDTMDF
{
    public string MDF_ENTIDAD;
    public string MDF_CENTRO_ALTA;
    public string MDF_CUENTA;
    public string MDF_ANIO;
    public string MDF_MES;

    [FieldNullValue("def")]
    public string MDF_SALDOS_MEDIOS;

    [FieldNullValue("def")]
    public string MDF_SALDO_DISPUE;

    public string MDF_SALDO_MAX_DEU;
    public string MDF_INTE_COBRAD;
    public string MDF_INTE_PAGADO;
    public string MDF_IMPU_RETENI;
}

(there is only part of this class (so huge).)

Any help?

Phoenix
  • 1,045
  • 1
  • 14
  • 22
codelikeprogrammerwoman
  • 1,429
  • 3
  • 14
  • 17
  • With a huge file, you should be using `FileHelperAsyncEngine`. See [this answer](http://stackoverflow.com/a/15234867/1077279) for an example. – shamp00 Jan 13 '15 at 15:08

1 Answers1

1

My solution is mark all fileds in class as [FieldOptional].

codelikeprogrammerwoman
  • 1,429
  • 3
  • 14
  • 17
  • You might need `FieldOptional` only on the last field. It looks like you might be bumping into [this bug](http://stackoverflow.com/a/10657781/1077279) which exists in FileHelpers 2.0.0.0 but is fixed in 2.9.9. – shamp00 Jan 13 '15 at 15:13