Getting a MemoryStream out of a ByteArray

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

For some reason I am drawing a blank on this, so I would be extremely
greatful if someone could help me out.

I am trying to get a MemoryStream out of a Byte array. How do I get it back
out?

I have a sub that calls a function:

Dim bByte() As Byte
bByte = ws.SQLGetUserDemographics()

Within that function I convert a memorystream to a byte array like this:

xmlms = ms.ToArray

I then pass that byte array back to the calling sub:

return xmlms

Now in my sub I want to get the memorystream back out of the byte array so i
can read it.

I am drawing a complete blank. Can someone help me out?
 
Scott,
Now in my sub I want to get the memorystream back out of the byte array so i
can read it.

A Byte array does not contain a MemoryStream, so you cannot "get the
memorystream back out of it" per se.

What you can do is create a new MemoryStream based on your byte array.

Something like:
Dim bByte() As Byte
Dim ms As New MemoryStream(bByte)

If you need or want the original MemoryStream for some reason I would pass
that as a parameter instead of the byte array itself.

Hope this helps
Jay
 
Scott,
My point was: If you don't need the MemoryStream I would pass the byte array
as Balena suggests, however if I needed the MemoryStream then I would pass
the MemoryStream!

In other words pass the least specific object that the routine/class needs.

As passing the lowest common denominator is one way to avoid coupling.

For example, it may be "better" to pass a Stream as a parameter, rather
specifically a MemoryStream. As with a Stream you can pass a FileStream,
MemoryStream, NetworkStream or any other kind of Stream and the
routine/class is none the wiser, allowing the routine/class to be used in
many more cases.

Hope this helps
Jay


SQLScott said:
Actually, the idea to pass it as a byte array was Fransesco Balena's (you
should know who he is).

However, your idea was perfect Jay. That worked beautifully and is exactly
what I needed. Thanks!

Scott
 
Back
Top