title: Copy MemoryStream to FileStream and save the file?
body: <p>I don't understand what I'm doing wrong here. I generate couple of memory streams and in debug-mode I see that they are populated. But when I try to copy <code>MemoryStream</code> to <code>FileStream</code> in order to save the file <code>fileStream</code> is not populated and file is 0bytes long (empty).</p>
  <p>Here is my code</p>
  <pre><code>if (file.ContentLength &gt; 0)
  {
      var bytes = ImageUploader.FilestreamToBytes(file); // bytes is populated
  
      using (var inStream = new MemoryStream(bytes)) // inStream is populated
      {
          using (var outStream = new MemoryStream())
          {
              using (var imageFactory = new ImageFactory())
              {
                  imageFactory.Load(inStream)
                              .Resize(new Size(320, 0))
                              .Format(ImageFormat.Jpeg)
                              .Quality(70)
                              .Save(outStream);
              }
              
              // outStream is populated here
              
              var fileName = &quot;test.jpg&quot;;
  
              using (var fileStream = new FileStream(Server.MapPath(&quot;~/content/u/&quot;) + fileName, FileMode.CreateNew, FileAccess.ReadWrite))
              {
                  outStream.CopyTo(fileStream); // fileStream is not populated
              }
          }
      }
  }
  </code></pre>