title: MemoryStream troubles
body: <p>I'm having some trouble using a MemoryStream</p>
  
  <p>We're using a 3rd party spreadsheet component (similar to excel), and I'm trying to save the data as html which they support through the <code>SaveHtml</code> method below. Seems very simple based on their documentation. Here is my code:</p>
  
  <pre><code>using (var memoryStream = new MemoryStream())
  {
     this.ActiveSheet.SaveHtml(memoryStream);
  
     memoryStream.Position = 0;
  
     using (var streamReader = new StreamReader(memoryStream))
     {
         var htmlData = streamReader.ReadToEnd();
     }
  }
  </code></pre>
  
  <p>I get an exception when I set the <code>memoryStream.Position = 0</code>:</p>
  
  <p><code>System.ObjectDisposedException: Cannot access a closed Stream.</code></p>
  
  <p>A quick look at their SaveHtml method in Reflector shows the following relevant lines:</p>
  
  <pre><code>public void SaveHtml(Stream stream)
  {
      StreamWriter writer = null;
  
      try
      {
          writer = new StreamWriter(stream) { AutoFlush = true };
  
          writer.Write(str);
      }   
      finally
      {
          if (writer != null)
          {
              writer.Close();
          }
      }
  }
  </code></pre>
  
  <p>I'm guessing because the streamWriter is closed by their code, we're out of luck. Closing the streamWriter, closes the underlying Stream, right?</p>
  
  <p>Any way to get around this?</p>
  
  <p>Thanks.</p>