Hello,

I have created a MemoryStream that is holding Binary Data. How do I get the
Data out of the Memory Stream into a file on my hard drive. All the
examples I have seen for a MemoryStream write the contents to the console.

Thanks
Chuck

Re: Stream Writer by Jay

Jay
Mon Oct 18 14:06:01 CDT 2004

Chuck,
You can use MemoryStream.ToArray to get the MemoryStream as an array of
bytes.

You can then use a FileStream to write this array of bytes to a file.

Alternatively you could read the MemoryStream from the beginning writing the
data to a FileStream...

However if your goal is to write Binary Data to a file, why not simply open
a FileStream directly instead of using an intermediate MemoryStream?

Hope this helps
Jay

"Charles A. Lackman" <Charles@CreateItSoftware.net> wrote in message
news:eaH2vRUtEHA.3772@TK2MSFTNGP10.phx.gbl...
> Hello,
>
> I have created a MemoryStream that is holding Binary Data. How do I get
> the Data out of the Memory Stream into a file on my hard drive. All the
> examples I have seen for a MemoryStream write the contents to the console.
>
> Thanks
> Chuck
>



Re: Stream Writer by Arne

Arne
Mon Oct 18 14:15:44 CDT 2004

Hi Charles!

"Charles A. Lackman" schrieb
> I have created a MemoryStream that is holding Binary Data. How do I get
> the Data out of the Memory Stream into a file on my hard drive. All the
> examples I have seen for a MemoryStream write the contents to the console.

In addition to the possibilities Jay listed you can use the
MemoryStream.WriteTo()-Method:

Dim buffer As Byte() = New Byte() {1, 2, 3, 4, 5}
Dim ms As MemoryStream = New MemoryStream(buffer)
Dim st As FileStream = New FileStream( _
"C:\test.bin", FileMode.Create)
ms.WriteTo(st)
st.Close()
ms.Close()


Cheers

Arne Janning



Re: Stream Writer by Charles

Charles
Mon Oct 18 14:19:44 CDT 2004

Hello I am retrieve binary data from a web service and need to write it to
disk. It will be a setup file or replacement files I have made for
applications.

This is where I am lost

the memory stream is filled.

ms.Seek(0, SeekOrigin.Begin)
Dim MyWriter as StreamWriter
MyWriter = New StreamWriter("C:\Test.Setup")

ms.read
mywriter.write(ms)

ms.close
mywriter.close
This does not work, what am I missing,

Thanks
Chuck


"Charles A. Lackman" <Charles@CreateItSoftware.net> wrote in message
news:eaH2vRUtEHA.3772@TK2MSFTNGP10.phx.gbl...
> Hello,
>
> I have created a MemoryStream that is holding Binary Data. How do I get
> the Data out of the Memory Stream into a file on my hard drive. All the
> examples I have seen for a MemoryStream write the contents to the console.
>
> Thanks
> Chuck
>



Re: Stream Writer by Charles

Charles
Mon Oct 18 14:22:23 CDT 2004

Thank You, Thank You, Thank You,

Chuck
:)
"Charles A. Lackman" <Charles@CreateItSoftware.net> wrote in message
news:eaH2vRUtEHA.3772@TK2MSFTNGP10.phx.gbl...
> Hello,
>
> I have created a MemoryStream that is holding Binary Data. How do I get
> the Data out of the Memory Stream into a file on my hard drive. All the
> examples I have seen for a MemoryStream write the contents to the console.
>
> Thanks
> Chuck
>



Re: Stream Writer by Jon

Jon
Mon Oct 18 16:23:11 CDT 2004

Charles A. Lackman <Charles@CreateItSoftware.net> wrote:
> Hello I am retrieve binary data from a web service and need to write it to
> disk. It will be a setup file or replacement files I have made for
> applications.
>
> This is where I am lost
>
> the memory stream is filled.
>
> ms.Seek(0, SeekOrigin.Begin)
> Dim MyWriter as StreamWriter
> MyWriter = New StreamWriter("C:\Test.Setup")
>
> ms.read
> mywriter.write(ms)
>
> ms.close
> mywriter.close
> This does not work, what am I missing,

One point here, apart from what the others have said: if you've got
binary data, you shouldn't use StreamWriter. Writers and Readers are
for text data. Streams are for binary data. Just use FileStream.

--
Jon Skeet - <skeet@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too