byte to stream csharp

Code Example - byte to stream csharp

                
                        byte[] file = File. ReadAllBytes("{FilePath}");
Stream stream = new MemoryStream(file);
                    
                
 

stream to byte array csharp

                        
                                public static byte[] GetBytes(Stream stream)
  {
   	var bytes = new byte[stream.Length];
   	stream.Seek(0, SeekOrigin.Begin);
   	stream.ReadAsync(bytes, 0, bytes.Length);
   	stream.Dispose();
   	return bytes;
  }
                            
                        
 

csharp write byte[] to stream

                        
                                static void Write(Stream s, Byte[] bytes)
{
    using (var writer = new BinaryWriter(s))
    {
        writer.Write(bytes);
    }
}