Possible Duplicate:
How do I convert byte[] to stream in C#?
I need to convert a byte array to a Stream . How to do so in C#?
It is in asp.net application.
FileUpload Control Name: taxformUpload
Program
byte[] buffer = new byte[(int)taxformUpload.FileContent.Length]; taxformUpload.FileContent.Read(buffer, 0, buffer.Length); Stream stream = ConvertToStream(buffer);
Streams are commonly written to byte arrays. The byte array is the preferred way to reference binary data in . NET. It can be used to data like the contents of a file or the pixels that make up the bitmap for an image.
From expirience I can say, that it does not copy the array. Be aware though, that you are unable to resize the memory stream, when using an array in the constructor.
You can re-use the MemoryStream by Setting the Position to 0 and the Length to 0. By setting the length to 0 you do not clear the existing buffer, it only resets the internal counters.
Easy, simply wrap a MemoryStream
around it:
Stream stream = new MemoryStream(buffer);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With