//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
//Parameters
DataTable table = new DataTable();
table.Columns.Add("FirstName", typeof(string));
table.Columns.Add("LastName", typeof(string));
table.Columns.Add("BirthDate", typeof(string));
DataRow row = table.NewRow();
row["FirstName"] = "John";
row["LastName"] = "Smith";
row["BirthDate"] = DateTime.Now.AddDays(-1).ToString();
table.Rows.Add(row);
//Order the output by Last Name, First Name, Birth Date
List<string> columnNameOrder = new List<string>();
columnNameOrder.Add("LastName");
columnNameOrder.Add("FirstName");
columnNameOrder.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.DataTableToCsvWriter(writer, table, columnNameOrder);
}
}
Console.WriteLine(File.ReadAllText(filePath));