How to convert Byte Array to Stream in C#
.Net - How do I convert byte[] to stream in C#?
If we need to get byte array from a stream object then you can use the
below code using System.IO namespace:
// Get byte array from stream
public byte[] GetBytesFromStream(Stream
stream)
{
byte[]
buffer = new byte[16
* 1024];
using
(MemoryStream ms = new
MemoryStream())
{
int
read;
while
((read = stream.Read(buffer, 0, buffer.Length)) > 0)
{
ms.Write(buffer, 0, read);
}
return
ms.ToArray();
}
}
How to convert Byte Array to Stream in C#
Reviewed by Ravi Kumar
on
11:32 PM
Rating:
No comments: