Click button to edit
QuickStart: Read Fixed File
Example of how to read a Fixed Length layout file (eg COBOL output):
Let's start with a simple file:
Input.txt
01010 Alfreds Futterkiste 13122005
12399 Ana Trujillo Emparedados y 23012000
00011 Antonio Moreno Taquería 21042001
51677 Around the Horn 13051998
99999 Berglunds snabbköp 02111999
We define the record layout:
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;
}
Read the values and write them to the Console:
Example.cs
var engine = new FixedFileEngine<Customer>();
Customer[] result = engine.ReadFile("input.txt");
foreach (var detail in result)
Console.WriteLine(" Client: {0}, Name: {1}", detail.CustId, detail.Name);
Console
Client: 1010, Name: Alfreds Futterkiste
Client: 12399, Name: Ana Trujillo Emparedados y
Client: 11, Name: Antonio Moreno Taquería
Client: 51677, Name: Around the Horn
Client: 99999, Name: Berglunds snabbköp