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