title: How to Write Custom HTML Document to file
body: <p>The basic question is: What is the best way to write data from a hierarchical set of objects to a file? The highest order parent has 1000's of children all with children (DOM style). Trying to traverse the tree and creating one big string which is then written to a file is throwing an out-of-memory exception while creating the string.</p>
  
  <p><em><strong>Details</em></strong>
  I've created a set of classes that make up an <em>HTML</em> document.<br>
  There was control that I needed that the pre-packaged <code>HtmlElement</code> and <code>HtmlDocument</code> didn't give. The <em>Document Object Model</em> is maintained throughout, with some similar methods and properties and such.<br>
  I'm using the custom classes to create a very large <em>HTML</em> document. When I say large, I mean on the order of over 2000 printed pages. It's doubtful that they will all be printed, but some will be.</p>
  
  <p>My base <code>HTMLElement</code> object, from which all other objects are derived, contains an <code>OuterHTML</code> property which, as expected, gets the full <em>HTML</em> of the calling object and the <em>HTML</em> of all child elements.<br>
  After the code which generates the report runs, I have my <em>HTMLDocument</em> object containing the entire report which needs to be written to a file. Here is where I keep running into problems.</p>
  
  <p>If I call <code>OuterHTML</code> on the <code>HTMLDocument</code> object, I get an <em>out of memory</em> exception. 
  Other reports have saved fine, but this is by far the largest report I've thrown at my <code>HTMLElement</code> object. My assumption is that the property call is generating too much text.</p>
  
  <p>I am basically just creating a new <em>.HTML</em> file, opening it for reading, and writing in all of the text. Like:</p>
  
  <pre><code>File.WriteAllText(FileName, HtmlDoc.OuterHTML)
  </code></pre>
  
  <p>So the question is: what is a better way to do this? </p>