Skip to content

Tutorial

Cinchoo edited this page May 27, 2017 · 14 revisions

Contents

Installing ChoETL

Cinchoo ETL can be downloaded from NuGet.

Use the GUI or the following command in the Package Manager Console:

Install-Package ChoETL

Add namespace to the program

using ChoETL;

That's it, you are ready to use Cinchoo ETL for extracting and generating various formatted files.

Loading file

To load any file (CSV, FixedLength, Xml), simple use the appropriate reader component to parse it. Sample below shows how to load CSV file (Emp.csv)

1,Tom
2,Carl
3,Mark

Load using iterator

foreach (var e in new ChoCSVReader("Emp.csv"))
    Console.WriteLine(e.ToStringEx());

Load using loop

var reader = new ChoCSVReader("Emp.csv");
object rec = null;
 
while ((rec = reader.Read()) != null)
    Console.WriteLine(rec.ToStringEx());

Writing file

To generate any file (CSV, FixedLength, Xml), simple use the appropriate writer component to generate it. Sample below shows how to create CSV file (Emp.csv)

1,Mark
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 ChoCSVWriter("Emp.csv"))
{
    parser.Write(objs);
}

Write each object

using (var parser = new ChoCSVWriter("Emp.csv"))
{
    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);
}