Search code examples
c#.netcsvimportfilehelpers

FileHelpers library CSV - why is one letter always removed from the last column on the right?


I have found a really great library to read CSV files - FileHelpers, but I have a strange problem with it. I would appreciate some help. Thanks in advance !

After mapping, I always get one letter removed from the last column on the right.

I'm using FileHelpers.dll Version 2.0.0 - DotNet 2.0 from FileHelpers_2_0_0_bin_docs_wizard.zip

For e.g. I have a CSV like this (some columns are quoted but some are not, it may change)

name;surname
"John";Smith
"Jack";Baker

And after reading file with:

FileHelperEngine<SemicolonsRow> engine = new FileHelperEngine<SemicolonsRow>();
engine.ErrorManager.ErrorMode = ErrorMode.SaveAndContinue;

res = engine.ReadFile("C:\\a.txt");

if (engine.ErrorManager.ErrorCount > 0)
engine.ErrorManager.SaveErrors("C:\\Log.txt");

I get this:

res[0].Col0 with name
res[0].Col1 with surnam  (lack of e at the end)
res[1].Col0 with John
res[1].Col0 with Smit  (lack of h at the end)

When I read file like this:

name;surname;country
"John";Smith;USA
"Jack";Baker;Canada

the problem is in third column - so I get: countr US Canad

My FileHelpers class:

[IgnoreEmptyLines()]
[DelimitedRecord(";")]
public sealed class SemicolonsRow
{
    [FieldOptional()]
    [FieldQuoted('"', QuoteMode.OptionalForRead, MultilineMode.AllowForRead)]
    public String Col0;

    [FieldOptional()]
    [FieldQuoted('"', QuoteMode.OptionalForRead, MultilineMode.AllowForRead)]
    public String Col1;

    [FieldOptional()]
    [FieldQuoted('"', QuoteMode.OptionalForRead, MultilineMode.AllowForRead)]
    public String Col2;

    [FieldOptional()]
    [FieldQuoted('"', QuoteMode.OptionalForRead, MultilineMode.AllowForRead)]
    public String Col3;
}  

Any ideas ?


Solution

  • That is an old issue with opcional fields and some other conditions that was solved after the release but we never get time to a full release

    You can download the last stable version from here that solve the problem:

    http://teamcity.codebetter.com/viewLog.html?buildId=lastSuccessful&buildTypeId=bt66&tab=artifacts&guest=1