how do i read a byte array into a stream?http://forums.asp.net/t/1330064.aspx/1?how+do+i+read+a+byte+array+into+a+stream+Mon, 06 Oct 2008 19:32:43 -040013300642665634http://forums.asp.net/p/1330064/2665634.aspx/1?how+do+i+read+a+byte+array+into+a+stream+how do i read a byte array into a stream? <p>&nbsp;Hi All.</p> <p>I have a method that returns an image in byte array form. I need to take this byte array and read it into a stream. Is this possible? If so, how?&nbsp;</p> <p>Appreciated.</p> <p>&nbsp;Thanks in advance. <br> </p> 2008-10-06T15:26:50-04:002665752http://forums.asp.net/p/1330064/2665752.aspx/1?Re+how+do+i+read+a+byte+array+into+a+stream+Re: how do i read a byte array into a stream? <p>Have a look at: <br> </p> <p>http://www.yoda.arachsys.com/csharp/readbinary.html</p> <p>http://www.dotnet-friends.com/articles/asp/artinasp03e650de-2b15-4fb1-9bdb-aad1a1e5ac5c.aspx <br> </p> 2008-10-06T16:14:33-04:002665789http://forums.asp.net/p/1330064/2665789.aspx/1?Re+how+do+i+read+a+byte+array+into+a+stream+Re: how do i read a byte array into a stream? <p>&nbsp;basically, the method returns a system.array object</p> <p>the data is like :</p> <p>(1) = 255<br> (2) = 216<br> (3) = 255</p> <p>etc etc </p> <p>when i try to cast it put it in a memory stream like this:</p> <p>Dim str As System.IO.MemoryStream = New System.IO.MemoryStream(arr)</p> <p>it gives me an error:</p> <p>System.InvalidCastException = {&quot;Unable to cast object of type 'System.Byte[*]' to type 'System.Byte[]'.&quot;} </p> <p>&nbsp;Any ideas? <br> </p> 2008-10-06T16:27:40-04:002665902http://forums.asp.net/p/1330064/2665902.aspx/1?Re+how+do+i+read+a+byte+array+into+a+stream+Re: how do i read a byte array into a stream? <p>You should pass by byteArray to stream...<br> </p> 2008-10-06T17:19:15-04:002665944http://forums.asp.net/p/1330064/2665944.aspx/1?Re+how+do+i+read+a+byte+array+into+a+stream+Re: how do i read a byte array into a stream? <p>&nbsp;how?</p> 2008-10-06T17:41:16-04:002666091http://forums.asp.net/p/1330064/2666091.aspx/1?Re+how+do+i+read+a+byte+array+into+a+stream+Re: how do i read a byte array into a stream? <p>It should be some thing like this..&nbsp;<pre class="prettyprint">Dim s As Stream = New MemoryStream(byteArray)</pre>&nbsp;</p> 2008-10-06T18:51:55-04:002666178http://forums.asp.net/p/1330064/2666178.aspx/1?Re+how+do+i+read+a+byte+array+into+a+stream+Re: how do i read a byte array into a stream? <p></p> <blockquote><span class="icon-blockquote"></span> <h4><strong>aspd </strong></h4> <br> &nbsp;how?<br> </blockquote> &nbsp; <br> <p></p> <p>Try this example below using ArrayList..</p> <p>&nbsp;</p> <pre class="prettyprint">Dim arr As New ArrayList() arr.Add(&quot;AAA&quot;) arr.Add(&quot;BBB&quot;) arr.Add(&quot;CCC&quot;) Dim byteArray As Byte() = New Byte(2) {} For i As Integer = 0 To arr.Count - 1 byteArray = DirectCast(arr(i), Byte()) Next 'Read byteArray to stream Dim stream As New System.IO.MemoryStream(byteArray)</pre>&nbsp;&nbsp; 2008-10-06T19:32:43-04:00