473,394 Members | 1,110 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Getting a MemoryStream out of a ByteArray

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?

--
Thanks,

Scott
Nov 21 '05 #1
2 2107
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
"SQLScott" <SQ******@discussions.microsoft.com> wrote in message
news:B1**********************************@microsof t.com... 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?

--
Thanks,

Scott

Nov 21 '05 #2
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" <SQ******@discussions.microsoft.com> wrote in message
news:6F**********************************@microsof t.com...
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

"Jay B. Harlow [MVP - Outlook]" wrote:
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
"SQLScott" <SQ******@discussions.microsoft.com> wrote in message
news:B1**********************************@microsof t.com...
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?

--
Thanks,

Scott


Nov 21 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Gambler | last post by:
Hi, I'm trying to download a memorystream to a .csv file on the users desktop. When I go to write out the memorystream through the byte array it seems to truncate at 1024 and I don't know how to...
14
by: John J. Hughes II | last post by:
Using the below code I am send multiple sterilized object across an IP port. This works fine if only one object is received at a time but with packing sometimes there is more then one object or...
3
by: Hitesh | last post by:
Hi, I am getting the response from another Website by using the HttpHandler in my current site. I am getting the page but all the images on that page are not appearing only placeholder are...
11
by: Rasmus Teglgaard | last post by:
Hi I need to know how to store the OpenfileDialog.OpenFile() in a memorystream. Do I need to do some kind of conversion before this works I can't write dim mem as new memorystream( mem =...
10
by: LoSTMaN | last post by:
Hi, I try to make a DragDrop to a Picturebox, to drag images from IE. But i'm stuck here : If (e.Data.GetDataPresent("DeviceIndependentBitmap")) Then PictureBox1.Image =...
4
by: vbdotnetmania | last post by:
I have the following snippet of code with bm being a succesfully stored bitmap (not including all the code just the relevant bits) Dim g As Graphics Dim g2 As Graphics Dim bm As Bitmap Dim bm2...
1
by: vbdotnetmania | last post by:
I have a memorystream of a bitmap, I want to send this over the network to a client app so it can receive the bitmap, I am dabbling with sockets and tcpclient's and ahve got a connection going but...
2
by: tony | last post by:
XslCompiledTransform xslt = new XslCompiledTransform(); ASCIIEncoding encodeToByteArray = new ASCIIEncoding(); MemoryStream inputStream = new MemoryStream(); MemoryStream outputStream = new...
11
by: Icemokka | last post by:
Hi, I'm need to upload a big file ( 600Mb+ ) to a BLOB field in MSSQL 2005. My code looks like this : fs = New FileStream(sFilePath, FileMode.Open) Dim ByteArray(fs.Length) As Byte...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.