title: Merging CSV files with different headers using CSVhelper C#
body: <p>When trying to merge multiple .csv files from a directory into one .csv file using CSVhelper. In the directory there are 50 .csv files, among these 50 files there are two sets of file structures, one with 7 columns and one with 6. Every file has the exact same first 5 headers however depending on the file the last two columns will change. </p>
  
  <p>Example of CSVfile format 1: <a href="https://i.stack.imgur.com/vZtsD.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/vZtsD.png" alt="enter image description here"></a></p>
  
  <p>Example of CSVfile format 2: <a href="https://i.stack.imgur.com/rI5BO.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/rI5BO.png" alt="enter image description here"></a></p>
  
  <p>Every file in the directory will hold either of these structures with different data in the columns. The output of the new file will have data from all the columns bar Action, Code and Error Message. If i use files only with the structure of example 1 the file comes together perfectly. However, if i include files with both structures and try and use 'ErrorIPAddress' from example 2 in my new file i get the following error:</p>
  
  <blockquote>
    <p>An unhandled exception of type 'CsvHelper.TypeConversion.CsvTypeConverterException' occurred in CsvHelper.dll</p>
  </blockquote>
  
  <p>On this line: `IEnumerable dataRecord = reader.GetRecords().ToList();</p>
  
  <p>My question is: How to use columns from one file thats not in the other? I have tried mapping it with the following:<code>Map(m =&gt; m.ErrorIPAddress).Index(5);</code> and i believe this is the line causing me the issue as if i comment it out the error doesn't persist however obviously i won't get the data i need into the new .csv. If i try and map by name with: <code>Map( m =&gt; m.ErrorIPAddress ).Name( "ErrorIPAddress" );</code> I get the error message that ErrorIPAddress is not in the .csv file which it won't be as not all files have that column.</p>
  
  <p>Output .csv format:<a href="https://i.stack.imgur.com/C0Jsl.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/C0Jsl.png" alt="enter image description here"></a></p>
  
  <p>The final column will be generated by the ErrorIPAddress column in format 2. </p>