I am trying to write a CSV file using the NuGet CsvHelper Package. When I run the controller action I’m seeing “Cannot access a closed file.”
SurveyResponseModel person = surveyResponseRepository.Get().Include(s => s.PersonModel).FirstOrDefault();
using (var csv = new CsvWriter(new StreamWriter("file.csv")))
{
csv.Configuration.HasHeaderRecord = false;
csv.Configuration.Delimiter = ',';
csv.WriteRecord(person);
}
I’m not sure what is causing this. Anybody know how I can get this to write a .CSV file?
I had to declare a specific path like: