title: Writing a Header using CsvHelper? C#
body: <p>I'm using CsvHelper. To write to a <code>.csv</code> file, I need a header based off of a class.</p>
  
  <p>I write the header manually and it works, but I need to be done automatically when it is read.</p>
  
  <p>All the documentation I can find says to use this expression, <code>writer.WriteHeader&lt;CSVDataFormat&gt;();</code> but that isn't working because it needs more work done to it.</p>
  
  <p>Here is the class that the header should be based off:</p>
  
  <pre><code>public class CSVDataFormat
  {
      public string FirstName { get; set; }
      public string LastName { get; set; }
      public float Wage { get; set; }
  }
  </code></pre>
  
  <p>Here is the code for the reading and writing:</p>
  
  <pre><code>private void ReadCSV(string ogCsvFile)
  {
          using (var streamReaederfileDir = new StreamReader(@ogCsvFile))
          {
              using (var streamWriterFileDir = new StreamWriter(Path.Combine(Path.GetDirectoryName(ogCsvFile), "New" + Path.GetFileName(ogCsvFile))))
              {
                  var reader = new CsvReader(streamReaederfileDir);
                  var writer = new CsvWriter(streamWriterFileDir);
  
                  writer.WriteHeader&lt;CSVDataFormat&gt;();
  
                  IEnumerable records = reader.GetRecords&lt;CSVDataFormat&gt;().ToList();
  
                  foreach (CSVDataFormat record in records)
                  {
                      record.Wage = record.Wage + (record.Wage / 10);
                      writer.WriteField(record.FirstName);
                      writer.WriteField(record.LastName);
                      writer.WriteField(record.Wage);
                      writer.NextRecord();
                  }
              }
          }
  }
  </code></pre>
  
  <p><strong>Update</strong></p>
  
  <p>This is the error I am getting when I run my code:</p>
  
  <blockquote>
    <p>An unhandled exception of type 'CsvHelper.CsvMissingFieldException' occurred in CsvHelper.dll</p>
    
    <p>Additional information: Fields 'FirstName' do not exist in the CSV file.</p>
  </blockquote>