title: Writing a memory stream to a file
body: <p>I have tried retrieving data in the json format as a string and writing it to a file and it worked great. Now I am trying to use MemoryStream to do the same thing but nothing gets written to a file - merely [{},{},{},{},{}] without any actual data.</p>
  
  <p>My question is - how can I check if data indeed goes to memory stream correctly or if the problem occurs somewhere else. I do know that myList does contain data.</p>
  
  <p>Here is my code:</p>
  
  <pre><code>MemoryStream ms = new MemoryStream();
  DataContractJsonSerializer dcjs = new DataContractJsonSerializer(typeof(List&lt;myClass&gt;));
  dcjs.WriteObject(ms, myList);
  
  using (FileStream fs = new FileStream(Path.Combine(Application.StartupPath,"MyFile.json"), FileMode.OpenOrCreate))
  {
                  ms.Position = 0;
                  ms.Read(ms.ToArray(), 0, (int)ms.Length);
                  fs.Write(ms.ToArray(), 0, ms.ToArray().Length);
                  ms.Close();
                  fs.Flush();
                  fs.Close();
   }
  </code></pre>