I am using the CSVHelper Component from NuGet. I have all of my data exporting successfully. However, I have several fields that are boolean type and return “true”/”false” to the csv file. My project requires that instead I output either “1” or “0” instead of “true”/”false”. What is the easiest way to achieve this?
var AllRecords = surveyResponseRepository.Get()
.Where(r => r.ProgramId == ProgramId);
string uniqueID = Guid.NewGuid().ToString();
var appData = Server.MapPath("~/CsvExport/" + uniqueID + ".csv");
using (var csv = new CsvWriter(new StreamWriter(appData)))
{
csv.Configuration.HasHeaderRecord = true;
csv.Configuration.Delimiter = ',';
csv.WriteRecords(AllRecords);
}
I believe you could inherit CsvWriter and override WriteField to something like this: