title: What is the best practice for storing a file upload to a MemoryStream (C#)?
body: <p>I need to temporary store a file upload to a MemoryStream. </p>
  
  <p>What would be the best method to do this using asp.net (3.5)?</p>
  
  <p>Here's what I have so far. It works (locally tested), but it does not look right to me.</p>
  
  <pre><code>protected void lnkUploadFile_Click(object sender, EventArgs e)
      {
          MemoryStream memStream = new MemoryStream();
  
          BinaryWriter sWriter = new BinaryWriter(memStream);
  
          foreach (byte b in flUpload.FileBytes)
          {
              sWriter.Write(b);
          }
  
          sWriter.Flush();
  
          // writing to file to verify file stream converted correctly
          FileStream fstream = new FileStream(@"C:/test/" + flUpload.FileName, FileMode.Create);          
          memStream.WriteTo(fstream);         
          fstream.Dispose();
  
          memStream.Dispose();
      }
  </code></pre>