CsvWriter csvWriter = new CsvWriter(); //Trial Mode
//CsvWriter csvWriter = new CsvWriter("place user name here", "place license key here"); //License Mode
List<Person> persons = new List<Person>();
Person person1 = new Person();
person1.FirstName = "John";
person1.LastName = "Smith";
person1.BirthDate = DateTime.Now.AddYears(-6);
persons.Add(person1);
Person person2 = new Person();
person2.FirstName = "Sara";
person2.LastName = "Smith";
person2.BirthDate = DateTime.Now.AddYears(-4);
persons.Add(person2);
string filePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "appendWriter.csv");
using (FileStream stream = new FileStream(filePath, FileMode.Create, FileAccess.Write))
{
using (TextWriter writer = new StreamWriter(stream))
{
for (int i = 0; i < persons.Count; i++)
{
bool outputHeader = i == 0;
csvWriter.AppendToCsvWriter(persons[i], writer, outputHeader);
}
}
}
Console.WriteLine(File.ReadAllText(filePath));