I am looking for a solution in C# language which can convert System.IO.Stream to byte[]. I have tried the below code but i am receiving byte[] as null. Can some one guide what i am missing from below code ? I am receiving from Alfresco Web service, no way i can read the file unless saving in to temp location.
private static byte[] ReadFile(Stream fileStream)
{
byte[] bytes = new byte[fileStream.Length];
fileStream.Read(bytes, 0, Convert.ToInt32(fileStream.Length));
fileStream.Close();
return bytes;
//using (MemoryStream ms = new MemoryStream())
//{
// int read;
// while ((read = fileStream.Read(bytes, 0, bytes.Length)) > 0)
// {
// fileStream.CopyTo(ms);
// }
// return ms.ToArray();
//}
}