Skip to content

QuickFixedLengthWrite

Cinchoo edited this page Jun 16, 2017 · 4 revisions

Writing FixedLength file

To generate FixedLength file, use the ChoFixedLengthWriter component to generate it. Sample below shows how to create FixedLength file (Emp.txt)

Id      Name      
1       Carl      
2       Jason     

Write list of objects

List<ExpandoObject> objs = new List<ExpandoObject>();
dynamic rec1 = new ExpandoObject();
rec1.Id = 1;
rec1.Name = "Mark";
objs.Add(rec1);
 
dynamic rec2 = new ExpandoObject();
rec2.Id = 2;
rec2.Name = "Jason";
objs.Add(rec2);
 
using (var parser = new ChoFixedLengthWriter("Emp.txt").WithFirstLineHeader().
      WithField("Id", 0, 8).
      WithField("Name", 8, 10))
{
    parser.Write(objs);
}

Write each object

using (var parser = new ChoFixedLengthWriter("Emp.txt").WithFirstLineHeader().
      WithField("Id", 0, 8).
      WithField("Name", 8, 10))
{
    dynamic rec1 = new ExpandoObject();
    rec1.Id = 1;
    rec1.Name = "Mark";
    parser.Write(item);

    dynamic rec1 = new ExpandoObject();
    rec1.Id = 2;
    rec1.Name = "Jason";
    parser.Write(item);
}

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

Cinchoo ETL - FixedLength Writer