//Example Class
public class Person
{
public string FirstName { get; set; }
public string LastName { get; set; }
public DateTime BirthDate { get; set; }
}
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.AddDays(-1);
persons.Add(person1);
//Order the output by Last Name, First Name, Birth Date
List<string> propertyOrder = new List<string>();
propertyOrder.Add("LastName");
propertyOrder.Add("FirstName");
propertyOrder.Add("BirthDate");
string filePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "testWriter.csv");
using (FileStream stream = new FileStream(filePath, FileMode.Create, FileAccess.Write))
{
using (TextWriter writer = new StreamWriter(stream))
{
csvWriter.ClassListToCsvWriter(writer, persons, propertyOrder);
}
}
Console.WriteLine(File.ReadAllText(filePath));