How to

convert stream to bytes array

Published: 2. February 2014 | Updated: 2. February 2014
License: Microsoft Public License (MS-PL)
Categories: Converting, Streams
Tags: C# Conversion
Was this snippet helpful for you? YESYES / NONO
Get Analyzant!

Check your entire website from code to content in minutes with Analyzant, the free analysis suite.

Free download at analyzant.com

Import namespaces

using System.IO;

Code

public static byte[] StreamToBytes(Stream stream)
{
    using (var memoryStream = new MemoryStream())
    {
        stream.CopyTo(memoryStream);
        return memoryStream.ToArray();
    }
}
Send us feedback about this snippet »



Related Snippets: