Skip to content

QuickFixedLengthLoad

Cinchoo edited this page Jun 24, 2017 · 14 revisions

Loading FixedLength file

To load FixedLength file, use ChoFixedLengthReader component to parse it. Sample below shows how to load FixedLength file (Emp.txt)

Id      Name      
1       Carl      
2       Mark      

Load using iterator

foreach (dynamic e in new ChoFixedLengthReader("Emp.txt").WithFirstLineHeader())
    Console.WriteLine("Id: " + e.Id + " Name: " + e.Name);

Load using loop

var reader = new ChoFixedLengthReader("Emp.txt").WithFirstLineHeader();
dynamic rec;
 
while ((rec = reader.Read()) != null)
    Console.WriteLine("Id: " + e.Id + " Name: " + e.Name);

Load with field specs

foreach (var e in new ChoFixedLengthReader("Emp.txt").WithFirstLineHeader().WithField("Id", 0, 8).WithField(8, 10))
    Console.WriteLine("Id: " + e.Id + " Name: " + e.Name);

Load using POCO object

public partial class Employee
{
	[ChoFixedLengthRecordField(0, 8)]
	public int Id { get; set; }
	[ChoFixedLengthRecordField(8, 10)]
	public string Name { get; set; }
}
foreach (var e in new FixedLengthReader<Employee>("Emp.txt"))
    Console.WriteLine("Id: " + e.Id + " Name: " + e.Name);

Please visit below article for detailed walk-through of Flat (FixedLength) file reader

Cinchoo ETL - FixedLength Reader