Answers for "how to append data using csvHelper in c#"

C#
0

how to append data using csvHelper in c#

using CsvHelper;

public void WriteDataToCsv(MsgEnvironmentData[] data, string csvPath)
{
           
       if (!File.Exists(csvPath))
       {
         using (var writer = new StreamWriter(csvPath))
         using (var csvWriter = new CsvWriter(writer,firstConfiguration))
          {

              csvWriter.WriteHeader<MsgEnvironmentData>();
              csvWriter.NextRecord();
              csvWriter.WriteRecords(data);
          }
       }
       else
       {
           using (var stream = new FileStream(csvPath, FileMode.Append))
           using (var writer = new StreamWriter(stream))
           using (var csvWriter = new CsvWriter(writer, secondConfiguration))
            {
                csvWriter.WriteRecords(data);
            }
        }
}
Posted by: Guest on February-17-2021

Code answers related to "how to append data using csvHelper in c#"

C# Answers by Framework

Browse Popular Code Answers by Language