title: In C#, how should I create a csv from parent-child table?
body: <p>My parent-child table looks like this:</p>
  
  <pre><code>ID, ParentID, Name, Population
  1, Null, Asia, 40
  2, Null, Africa, 20
  3, 1, China, 10
  4, 3, Tibet, 5
  </code></pre>
  
  <p>(around 1000 rows and the levels of the tree can vary. User will keep entering new rows)</p>
  
  <p>I want to achieve a csv file that looks like this:</p>
  
  <pre><code>Level1, Level2, Level3, Population
  Asia, Null, Null, 40
  Africa, Null, Null, 20
  Asia, China, Null, 10
  Asia, China, Tibet, 5
  </code></pre>
  
  <p>How do I create a csv file like this from parent-child table?  First challange is to find max number of levels of parent-child table and then create csv headers.  Second challange is to then put null for levels that do not have value.</p>
  
  <p>Please note that users will keep entering new lines... not sure if I should load the parent-child table in xml format and then start reading xml file... please suggest some way.  Thank you</p>