Important
-
DataLink feature is outdated and will be rewritten
The support to interact with other datasources is from the old 1.1 or 2.0 days. We will be rewriting this feature for the next release using lambda expressions, Task and other advanced features of .NET
-
Excel support is only for basic scenarios
The current implemented Excel support is only for basic scenarios. If you need custom formatting, charts, etc. you must go for a custom code. It's strongly recommended to directly use the NPOI library
FAQ
-
My file has headers, how can I ignore it ?
You must use the [IgnoreFirst] attribute. For the footer line you can use the [IgnoreLast] attribute.
-
I want to write a file with headers
You must use engine.HeaderText = engine.GetFileHeader() before you call WriteFile
-
Not all the characters from the original file are read
You have a problem with the Encoding. You can pass the encoding to the engines new FileHelperEngine
(Encoding.UTF8) -
How can I skip certain lines when reading a file
You can capture the BeforeRead event or use the INotifyRead interface
-
My DateTime field has a different format
Use this attribute with your format: [FieldConverter(ConverterKind.Date, "M-d-yyyy" )] Check the Converters page for more info
Performance
-
Try to use FileHelperAsyncEngine
When reading or writing a large number of records, we recommend using FileHelperAsyncEngine; it will work faster and use a ton less memory
-
Use the FieldValueDiscarded attribute for fields that you don't use
If your record class has some fields that are not used, the library will discard the value of fields marked by this attribute
Debugging
-
Use all the values of the FileHelper Exceptions
We work hard to provide great context info in all exceptions to assist in debugging. ConvertException
A brief description of the attributes and the usage.
Fixed Length Records
Attribute Read Write FixedLengthRecord
Indicates a fixed length record fileX X IgnoreFirst X IgnoreLast X IgnoreEmptyLines X ConditionalRecord X Delimited Records
Attribute Read Write DelimitedRecord
Indicates a delimited record fileX X IgnoreFirst X IgnoreLast X IgnoreEmptyLines X ConditionalRecord X
Fixed Length Fields
Attribute Read Write FieldFixedLength
Indicates a length of the fieldX X FieldConverter X X FieldQuoted X X FieldInNewLine? X X FieldHidden
The library will ignore this fieldX X FieldOptional X FieldNullValue X FieldTrim ? X FieldAlign X Delimited Fields
Attribute Read Write FieldDelimiter
Indicates a new field end markerX X FieldConverter X X FieldQuoted X X FieldInNewLine? X X FieldHidden
The library will ignore this fieldX X FieldOptional X FieldNullValue X - - Arguments for the Default Converters of the library.
Here is a list of the parameters that you can give to the default converters:
ConverterKind.Date
Arg1: A string with the DateTime format that the engine passes to the DateTime.Parse function.
Arg2: A string with the encoding used for string convertions
Examples:
You can find all the supported format strings in the MSDN docs for DateTime.ParseExact.
Here are all supported cultures.ConverterKind.Double, ConverterKind.Single and ConverterKind.Decimal
Arg1: A string with the character to be used as DecimalSeparator. Valid Values: "." or ",". By default: "."
Examples:
Integer Converters
ConverterKind.Int16, ConverterKind.Int32, ConverterKind.Int64, ConverterKind.Byte,
ConverterKind.UInt16, ConverterKind.UInt32, ConverterKind.UInt64, and ConverterKind.SByteArg1: A string with the character to be used as DecimalSeparator. Valid Values: "." or ",". By default: "."
WARNING: The library requires a decimal separator here and internally creates the group separator with the counterpart (for example if you provide "." it uses ",")
Examples:
ConverterKind.Boolean
Arg1: A string that represents the True value
Arg2: A string that represents the False valueBy default, this converter takes the strings "True" (case insensitive) and "1" as true. The values "True" and "False" are returned when converting the field to string.
Examples:
Best Practices Analyzer and Quick Fixes for the library
This Roslyn Analyzer helps you to use the library in the right way.
For example when you use a non generic engine the analyzer suggest you to use the generic version:
Quick Fixes
- Recommends to use the generic version when you use an engine with a typeof() in the constructor
- Suggest to use [FieldHidden] instead of [FieldIgnored] or [FieldNotInFile]
- Use FileHelpers.Dynamic instead of FileHelpers.RunTime namespace
-
Use IComparable
instead of the obsolete IComparableRecord - Check that record class contains valid record attributes
- Check that record class contains any field
- Convert engine.ReadFile in async version with foreach
Global Install
Install the extension and it will be available for all projects:
Download from Visual Studio GalleryNuGet Install
Use the NuGet Package Version and it will work only in installed projects
FileHelpers.Analyzer in NuGetInstructions when you upgrade from older version of the library
There are a lot of changes from that version. See the changelog.
The breaking changes are:
[FieldIgnored] => [FieldHidden]
The attribute was renamed to align with the real meaning
IComparableRecord<T> => IComparable<T>
We will remove the custom compararer and use the framework one
This release has little breaking changes:
[FieldIgnored] => [FieldHidden]
The attribute was renamed to align with the real meaning
IComparableRecord<T> => IComparable<T>
We will remove the custom compararer and use the framework one
INotifyRead and INotifyWrite now are non generic
In older versions when you implemented notifications via interfaces you must provide the same type of Record to get proper notification. From 3.1 you use them with out <> and the same is valid for the method signature:
Check the example