In my current project, I used File Helpers, and I wasn't disappointed !
Edit: As a sample of how simple it is, here is one of the classes I'm using. Everything works with attributes. (The sample is in VB.Net, but you'll get the idea)
<DelimitedRecord(";")> _
<IgnoreFirst(1)> _
<IgnoreEmptyLines()> _
Public Class ClientsClass
<FieldConverter(ConverterKind.Date, "dd/M/yyyy"), FieldQuoted(QuoteMode.OptionalForBoth)> Public DateField As Date
<FieldTrim(TrimMode.Both), FieldQuoted(QuoteMode.OptionalForBoth)> Public ClientCountry As String
<FieldTrim(TrimMode.Both), FieldQuoted(QuoteMode.OptionalForBoth)> Public AccountId As String
<FieldTrim(TrimMode.Both), FieldQuoted(QuoteMode.OptionalForBoth)> Public Name As String
<FieldTrim(TrimMode.Both), FieldQuoted(QuoteMode.OptionalForBoth)> Public FNumber As String
End Class
So basically, you create a class where each field is a field in your CVS file (order DOES matter), and then you add the attributes which will tell what treatment must be applied to the field (such as trimming, converting, ...). You can also add class properties, like <DelimitedRecord(";")>
, which tells which separator is used in the file, or IgnoreFirst(1)
, which tells the engine to not parse the first line. Every attribute is explained in their documentation, and the website has many samples for you to learn.
Then, parsing the file to the class is really easy:
Dim filePath as string = "Path to your file.csv"
Dim fhe As New FileHelperEngine(Of ClientsClass)
Dim vals as ClientClass() = CType(fhe.ReadFile(filePath), ClientClass())
And you get an array containing 1 ClientClass
object per parsed line.
Note that they also built a tool which helps you to create your classes, which can be downloaded on their website.