google-site-verification=ECX1M6_Vb39ty4VtQDXQce6wOjmPTxSettd3hTIZb9Q

How to convert Byte Array to Stream in C#

random

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: 5

No comments:

All Rights Reserved by Etechpulse © 2012 - 2017

Contact Form

Name

Email *

Message *

Powered by Blogger.