title: How to prewrite header before list all data in text file with c#
body: <p>I have example data like this</p>
  
  <pre><code>FamilyID;name;gender;DOB;Place of birth;status
  1;nicky;male;01-01-1998;greenland;married
  1;sonia;female;02-02-1995;greenland;married
  2;dicky;male;04-01-1995;bali;single
  3;redding;male;01-05-1996;USA;single
  3;sisca;female;05-03-1994;australia;married
  </code></pre>
  
  <p>i must separate all data  by familyID</p>
  
  <p>i already success to separate the data by family ID
  so the result is</p>
  
  <p>File 1:</p>
  
  <pre><code>1;nicky;male;01-01-1998;greenland;married
  1;sonia;female;02-02-1995;greenland;married
  </code></pre>
  
  <p>File 2:</p>
  
  <pre><code>2;dicky;male;04-01-1995;bali;single
  </code></pre>
  
  <p>File 3:</p>
  
  <pre><code>3;redding;male;01-05-1996;USA;single
  3;sisca;female;05-03-1994;australia;married
  </code></pre>
  
  <p>The problem is , the header is missing, for each file , i expect it to be like</p>
  
  <p>Example for file 1 :</p>
  
  <pre><code>FamilyID;name;gender;DOB;Place of birth;status
  1;nicky;male;01-01-1998;greenland;married
  1;sonia;female;02-02-1995;greenland;married
  </code></pre>
  
  <p>etc.</p>
  
  <p>This is the code i write</p>
  
  <pre><code>DateTime date = DateTime.Now;
              string tgl = date.Date.ToString("dd");
              string bln = date.Month.ToString("d2");
              string thn = date.Year.ToString();
              string tglskrg = thn + "/" + bln + "/" + tgl;
  
              string filename = ("C:\\Users\\Documents\\My Received Files\\exampledata.txt");
              string[] liness = File.ReadAllLines(filename);
              string[] col;
  
              var lines = File.ReadAllLines(filename);
  
              // group by first value
              var groups = lines.Skip(1)
                    .Select(x =&gt; x.Split(';'))
                    .GroupBy(x =&gt; x[0]).ToArray();
  
              // iterate groups write the joined lines back to a new file with the key name
              foreach (var group in groups)
              {
                  Console.WriteLine(group);
                  File.WriteAllLines(@"C:\\Users\\Documents\\My Received Files\\exampledata_"+group.Key+".txt", group.Select(x =&gt; string.Join(";", x)));
              }
  
              ...//line of code to zip file(already done too)
  
  </code></pre>
  
  <p>Maybe there is something i wrong or miss ?</p>
  
  <p>thanks for the help</p>
  
  <p>And i make it in visual express c# 2010, console application</p>