One of the simplest way to convert a stream to byte array in C# 4.0 is to use the MemoryStream and perform the CopyTo operation on the source stream to the Memory Stream. Below is a sample code snippet on how to convert a stream to byte array in C# 4.0. Learn C and C++ Programming C is a powerful system programming language, and C++ is an excellent general purpose programming language with modern bells and whistles. Sep 10, 2011 - Code snippet to convert stream as file attachment to download in asp.net. ToString()); Response.ContentType = 'application/octet-stream'; Response. NET MVC Handle Web Exception raised from HttpWebRequest in C#.