By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,050 Members | 1,703 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,050 IT Pros & Developers. It's quick & easy.

ADODB.Stream into byte array

P: n/a

How do I convert ADODB.Stream into an array of bytes?

Thank you.
Sep 26 '06 #1
Share this Question
Share on Google+
2 Replies


P: n/a
There really isn't a direct way to do this. The only workaround I see
is to call the SaveToFile method on the stream, and then read the bytes from
the file.

You might try and cast the Stream object to an IPersistMemory interface
instance (it is a COM interface, you might have to define it if it isn't
already defined somewhere). If that works, then you can write the contents
directly to a byte array. Either that, or the IStream COM interface (at
which point, you could read characters from the stream, and then write them
to your byte array).

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"bill tie" <bi*****@discussions.microsoft.comwrote in message
news:7A**********************************@microsof t.com...
>
How do I convert ADODB.Stream into an array of bytes?

Thank you.


Sep 26 '06 #2

P: n/a

Nicholas, thank you for your reply.

I've used IStream. I'm getting a byte array and can work with it. This is
my code:

IStream iStream = (IStream)adodbStream;
byte[] byteArray = new byte[adodbStream.Size];
IntPtr ptrCharsRead = IntPtr.Zero;
iStream.Read(byteArray, adodbStream.Size, ptrCharsRead);

I fudged this. I'm not sure what the IntPtr business is. The documentation
says "ptrCharsRead" is a pointer to a ULONG variable that receives the actual
number of bytes read from the stream object.

How do I print the value of the ULONG variable?
Sep 26 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.