Try moving to the beginning of the
MemoryStream
before trying to read it:
ms.Seek(0L, SeekOrigin.Begin);
ms.Read(bytes, 0, (int)ms.Length);
file.Write(bytes, 0, bytes.Length);
Alternatively, use the
ToArray
method:
byte[] bytes = ms.ToArray();
file.Write(bytes, 0, bytes.Length);
Or use the
CopyTo
method:
ms.CopyTo(file);