FileHelpers - Write Fixed File

  • 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. QuickStart
  3. Write Fixed File
Previous: Read Fixed File
Next: Read or Write Record by Record
Click button to edit
QuickStart: Write Fixed File
Example of how to write a Fixed Record File

To write a fixed length file like this:

Output.txt
1Antonio Moreno Taquería       01052009
2Berglunds snabbköp            02052009
RecordClass.cs
[FixedLengthRecord()]
public class Customer
{
    [FieldFixedLength(5)]
    public int CustId;

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

    [FieldFixedLength(8)]
    [FieldConverter(ConverterKind.Date, "ddMMyyyy")]
    public DateTime AddedDate;
}

Now just create some records and write them with the Engine

Example.cs
var engine = new FileHelperEngine<Customer>();

var customers = new List<Customer>();

var order1 = new Customer() {
    CustId = 1,
    Name = "Antonio Moreno Taquería",
    AddedDate = new DateTime(2009, 05, 01)
};
var order2 = new Customer() {
    CustId = 2,
    Name = "Berglunds snabbköp",
    AddedDate = new DateTime(2009, 05, 02)
};

customers.Add(order1);
customers.Add(order2);

engine.WriteFile("Output.Txt", customers);
Console
1Antonio Moreno Taquería       01052009
2Berglunds snabbköp            02052009

Copyright © 2020 Devoo - Marcos Meli All rights reserved. Template Design by GeeksLabs