Click here to Skip to main content
15,885,309 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
how to convert stream reader into byte array???
Posted
Updated 1-Nov-17 1:06am
Comments
Tomas Takac 29-Oct-15 9:03am    
You just need to read the stream into the array. What's the problem with that?
Nathan Minier 29-Oct-15 9:04am    
A stream reader is just that, a reader.

You can copy the stream itself to a MemoryStream and use the handy .ToByteArray() which that class provides. If it already is a memory stream, well problem solved.
Sergey Alexandrovich Kryukov 29-Oct-15 10:41am    
The question makes no sense. Do you want just to read an array? Any problems?
—SA

C#
byte[] result;
using (var streamReader = new MemoryStream())
{
    InputStream.CopyTo(streamReader);
    result = streamReader.ToArray();
}

You mean this, right ?
-KR
 
Share this answer
 
Comments
NagaNimesh 11474558 29-Oct-15 11:00am    
tanq..
Try:
C#
byte[] data;
using (StreamReader sr = new StreamReader(@"D:\temp\MyPic.jpg"))
    {
    using (MemoryStream ms = new MemoryStream())
        {
        sr.BaseStream.CopyTo(ms);
        data = ms.ToArray();
        }
    }
 
Share this answer
 
Comments
NagaNimesh 11474558 29-Oct-15 11:00am    
tanq..

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900