c# convert system.IO.Stream to Byte[]
byte, c#, stream
Solution
If you are reading a file just use the File.ReadAllBytes Method:
byte[] myBinary = File.ReadAllBytes(@"C:\MyDir\MyFile.bin");
Also, there is no need to CopyTo a MemoryStream just to get a byte array as long as your sourceStream supports the Length property:
byte[] myBinary = new byte[paramFile.Length];
paramFile.Read(myBinary, 0, (int)paramFile.Length);
Problem
I would like to know how to convert a stream to a byte. I find this code, but in my case it does not work: ``` var memoryStream = new MemoryStream(); paramFile.CopyTo(memoryStream); byte[] myBynary = memoryStream.ToArray(); myBinary = memoryStream.ToArray(); ``` But in my case, in the line paramFile.CopyTo(memoryStream) it happens nothing, no exception, the application still works, but the code not continue with the next line. Thanks.