FileHelpers - FixedLengthRecord FixedMode.AllowLessChars

  • Contact / Feedback
  • Introduction
  • Download
  • Quick Start
  • Must Read
  • Examples
    • QuickStart
      • Read Delimited File
      • Write Delimited File
      • Read Fixed File
      • Write Fixed File
      • Read or Write Record by Record
      • Autoproperties
    • Missing Values
      • Handle Missing Values with Nullable
      • Handle Missing Values With FieldNullValue
    • Attributes
      • FieldTrim
      • FieldOrder
      • FixedLengthRecord FixedMode.AllowLessChars
    • Converters
      • Enum Converter
      • Custom Converter
    • Events And Notification
      • INotifyRead Interface
      • INotifyWrite Interface
      • Before/After Read Event Handling
      • Before/After Write Event Handling
    • ErrorHandling
      • ErrorMode.ThrowException
      • ErrorMode.IgnoreAndContinue
      • ErrorMode SaveAndContinue
    • Advanced
      • Dynamic Engine Options
      • Multiple Delimiters
      • Multi Record Processing
      • Smart Format Detector
    • Sorting
      • Sort Big File with Record Class
      • Sort Big File without Record Class 1
      • Sort Big File without Record Class 2
    • MasterDetail
      • Master Detail Custom Selector
      • Master Detail Common Selector
  • Credits
  • Invite us a beer
  • Contribute
  • Source Code
  • Api Docs (Sandcastle)
  1. Examples
  2. Attributes
  3. FixedLengthRecord FixedMode.AllowLessChars
Previous: FieldOrder
Next: Enum Converter
Click button to edit
Attributes: FixedLengthRecord FixedMode.AllowLessChars
Options when working with fixed files where not all records have same length:
Input.txt
01010 Alfreds Futterkiste          13122005
12399 Ana Trujillo Emparedados y   23012000
00011 Antonio Moreno Taquería      042001
51677 Around the Horn              13051998
99999 Berglunds snabbköp           111999
//-> The Record Mapping class:
RecordClass.cs
[FixedLengthRecord(FixedMode.AllowLessChars)]
public class Customer
{
    [FieldFixedLength(5)]
    public int CustId;

    [FieldFixedLength(30)]
    [FieldTrim(TrimMode.Both)]
    public string Name;

    [FieldFixedLength(8)]
    [FieldConverter(ConverterKind.DateMultiFormat, "ddMMyyyy", "MMyyyy")]
    public DateTime AddedDate;
}
//-> Iterating over the records:
Example.cs
var engine = new FixedFileEngine<Customer>();
Customer[] result = engine.ReadFile("input.txt");

foreach (var detail in result) {
    Console.WriteLine(" Client: {0},  Date: {1}",
        detail.CustId,
        detail.AddedDate.ToString("dd-MM-yyyy"));
}
Console
Client: 1010,  Date: 13-12-2005
Client: 12399,  Date: 23-01-2000
Client: 11,  Date: 01-04-2001
Client: 51677,  Date: 13-05-1998
Client: 99999,  Date: 01-11-1999
Copyright © 2020 Devoo - Marcos Meli All rights reserved. Template Design by GeeksLabs