title: Serializing a memorystream object to string
body: <p>Right now I'm using XmlTextWriter to convert a MemoryStream object into string. But I wan't to know whether there is a faster method to serialize a memorystream to string.</p>
  
  <p>I follow the code given here for serialization - <a href="http://www.eggheadcafe.com/articles/system.xml.xmlserialization.asp" rel="noreferrer">http://www.eggheadcafe.com/articles/system.xml.xmlserialization.asp</a></p>
  
  <p><strong>Edited</strong></p>
  
  <p><strong>Stream to String</strong></p>
  
  <pre><code>ms.Position = 0;
  using (StreamReader sr = new StreamReader(ms))
  {
      string content = sr.ReadToEnd();
      SaveInDB(ms);
  }
  </code></pre>
  
  <p><strong>String to Stream</strong></p>
  
  <pre><code>string content = GetFromContentDB();
  byte[] byteArray = Encoding.ASCII.GetBytes(content);
  MemoryStream ms = new MemoryStream(byteArray); 
  byte[] outBuf = ms.GetBuffer(); //error here
  </code></pre>