I would like to export my class in .csv file, i follow this comment : <https://stackoverflow.com/a/38088636/10152334>

but when i export (in Buses\_Data.Buses\_List), i have wrong data output, all data are on same line :

[![enter image description here](https://i.stack.imgur.com/Xzoi3.png)](https://i.stack.imgur.com/Xzoi3.png)

```
public void ExportToCSV(Buses_Data classToExport, string filepath)
    {
        try
        {
            if (File.Exists(filepath))
            {
                Console.WriteLine("Le fichier existe");
                System.IO.File.Delete(filepath);
                Console.WriteLine("l'ancien fichier à été supprimé");
            }

            Console.WriteLine("Export :...");

            using (StreamWriter sw = new StreamWriter(filepath))
            using (CsvWriter cw = new CsvWriter(sw))
            {
                cw.WriteHeader<Bus>();

                foreach (Bus emp in classToExport.Buses_List)
                {
                    cw.WriteRecord<Bus>(emp);
                }
            }

            Console.WriteLine("Export CSV: OK");
        }
        catch (Exception i)
        {
            Console.WriteLine("Error ! " + i);
        }
    }

```

I don't know why the code doesn't work

Edit : 
Wrong output:
[![Wrong output](https://i.stack.imgur.com/qaDZ4.png)](https://i.stack.imgur.com/qaDZ4.png)

Right output (Data not corresponding)
[![Right output (Data not corresponding) ](https://i.stack.imgur.com/bN4DU.png)](https://i.stack.imgur.com/bN4DU.png)

Edit 2 : 
I tried this comment : [Enforce LF line endings with CsvHelper](https://stackoverflow.com/questions/28420135/enforce-lf-line-endings-with-csvhelper)

```
using (StreamWriter sw = new StreamWriter(filepath))

            using (CsvWriter cw = new CsvWriter(sw))
            {
                cw.WriteHeader<Bus>();

                foreach (Bus emp in classToExport.Buses_List)
                {

                    cw.WriteRecord<Bus>(emp);
                    sw.NewLine = "\n";
                    cw.NextRecord();
                }
            }

```

I have better result but i Bus N°1 is on first line, not in second line

[![enter image description here](https://i.stack.imgur.com/OZDo8.png)](https://i.stack.imgur.com/OZDo8.png)

Solution :

```
using (StreamWriter sw = new StreamWriter(filepath))
            using (CsvWriter cw = new CsvWriter(sw))
            {
                cw.WriteHeader<Bus>();
                cw.NextRecord();
                foreach (Bus emp in classToExport.Buses_List)
                {

                    cw.WriteRecord<Bus>(emp);
                    //sw.NewLine = "\n";
                    cw.NextRecord();
                }
            }

```