Øyvind Bråthen
Øyvind Bråthen

Reputation: 60694

Reading csv file with newlines inside strings fails

I'm trying to read a csv file using the FileHelpers library.

One of the problematic lines look like this:

4159948;1;31;2018-01-03 11:11:25.0;"Feil funnet på skiltbelysning mot Ryggevn. Isolasjonsresistansen etter frakobling: 1,2Mohm";2018-01-03 11:11:25.0;MOSS ELEKTRO AS;MOSS ELEKTRO AS;1;824;251812;MOSS ELEKTRO AS;" MOSS ELEKTRO AS"

So there is a field that has a newline inside it, but it's look proper since the file has added the text inside " on both sides.

However, when reading the file I get the following error:

Line: 2 Column: 35. Delimiter ';' not found after field 'k__BackingField' (the record has less fields, the delimiter is wrong or the next field must be marked as optional).

So it does not understand the line break.

Are there any way to get this to work with FileHelpers? If not, are there any other library that I can use that handle this properly?

Upvotes: 0

Views: 297

Answers (1)

Øyvind Bråthen
Øyvind Bråthen

Reputation: 60694

The problem was that in the class that I was mapping the file to, the property that was goingto be mapped to the column containing the multiline field had to have the attribute [FieldQuoted('"')] to understand that the field could be quoted with ". When adding this attribute the parsing worked just fine.

Upvotes: 0

Related Questions