This tutorial will show you how to convert a byte array from a stream in C#.NET
You can use the MemoryStream to convert a stream to byte array
public byte[] ConvertStreamToArray(Stream input)
{
using (MemoryStream ms = new MemoryStream())
{
input.CopyTo(ms);
return ms.ToArray();
}
}
another version using the Read method to read data from a stream, then write to a buffer
public byte[] ConvertStreamToBytes(Stream input)
{
byte[] buffer = new byte[16*1024];
using (MemoryStream ms = new MemoryStream())
{
int read;
while ((read = input.Read(buffer, 0, buffer.Length)) > 0)
{
ms.Write(buffer, 0, read);
}
return ms.ToArray();
}
}