Jose Saiz

Jose Saiz

  • 1.4k
  • 243
  • 98.6k

How to convert .OutputStream to byte[] array

Mar 21 2020 11:36 AM
Hi Guy I am having dificulty trying to convert from HttpContext.Current.Response.OutputStream to a byte[] array
 
This is my code
  1. byte[] myBuff = new byte[16384];  
  2. using (var memoryStream = new System.IO.MemoryStream())  
  3. {  
  4. HttpContext.Current.Response.OutputStream.CopyTo(memoryStream);  
  5. myBuff = memoryStream.ToArray();  
  6. }  
  7.    
but I get the following error message "Stream does not support reading." 
the  HttpContext.Current.Response.OutputStream carries an image contentype="image/GIF"
 
Any Idea what I'm missing or doing wrong?
 
TIA 

Answers (2)