سؤال

I built a program using FileHelpers to parse CSV files and it works wonders, except I'm running into an issue. Some of the files - but not all - have a number of extra lines in the end with information that does not pertain to actual fields.

like so

...
31,4104019, ,,1043,,,0,,Ventas Total Credito,1,1,277.98,0,0,0,0,21.5040000000,V,
31, ,11212302,,1043,,,0,,Ventas Total Credito,1,1,33.28,0,0,0,0,21.5040000000,V,
31, ,11212307,,1043,,,0,,Ventas Total Credito,1,1,277.98,0,0,0,0,21.5040000000,V,

;Importado="01/11/2013"
 //blank line here too

I know FileHelpers has the

[IgnoreLast(3)] 
public class whatever...

option, but as only some of the files have those extra 3 lines, Using this for all could result in the last 3 records being ignored for some files.

Is there any way to tell it when to ignore a line? Or should I read the file separately first and remove those lines myself?

هل كانت مفيدة؟

المحلول

You can use the BeforeReadRecord event or implement in the record INotifyRead interface that is more simple.

In both cases use e.SkipThisRecord = true; in the cases that you need to discard

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top