473,473 Members | 2,026 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Stream Writer

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
Jul 21 '05 #1
5 1344
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" <Ch*****@CreateItSoftware.net> wrote in message
news:ea**************@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

Jul 21 '05 #2
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
Jul 21 '05 #3
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" <Ch*****@CreateItSoftware.net> wrote in message
news:ea**************@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

Jul 21 '05 #4
Thank You, Thank You, Thank You,

Chuck
:)
"Charles A. Lackman" <Ch*****@CreateItSoftware.net> wrote in message
news:ea**************@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

Jul 21 '05 #5
Charles A. Lackman <Ch*****@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 - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Jul 21 '05 #6

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

Similar topics

18
by: JG | last post by:
Does anyone know a standard (or supported on Linux, Mac, Win32) way to clear a read stream buffer (standard ANSI C file stream)? I would even settle for a platform specific way of doing it. ...
5
by: andrewcw | last post by:
I have an object to serialize. TextWriter writer = new StreamWriter("test.xml"); serializer.Serialize(writer,obj); writer.Close(); but below does not, why ?? I have a file that I will have...
1
by: Martin | last post by:
Hi Im trying to make a Client/Server where im going to encrypt the stream but i cant get it to work. I can recieve and send as long as im not trying to send/recieve encrypted. but when i am i cant...
0
by: a | last post by:
Save text file as html kloepper 17:42 23 Jul '04 I'm using httpwebresponse and a StringBuilder to return a stream that originates as a file with the .txt suffix (My download code converts the html...
1
by: Ryan Ternier | last post by:
I'm writing a file out using StreamWriter. What i'm outputting is a 6,398 lines of stupid Jscript arrays. Yes the system needs to be very very dynamic, and they don't want a page reload. The...
8
by: Marc Gravell | last post by:
I want to write a method that will accept a stream as a parameter, and which will write xml to the stream (based in reality on database results) using the XmlTextWriter class. However, this insists...
7
by: .... | last post by:
Hi I have an existing function which has a stream object (inmsg.BodyPart.Data). I'm trying to search and replace the stream object in the most efficient way possible This is my attempt below,...
10
by: John Kraft | last post by:
Hello all, I'm experiencing some, imo, strange behavior with the StreamReader object I am using in the code below. Summary is that I am downloading a file from a website and saving it to disk...
2
by: Mikus Sleiners | last post by:
I'm trying to write new stream from string and i can't figure out why my memory stream instance is null after i have writen to it with stream writer. Here is an example. MemoryStream stream =...
1
by: pax82 | last post by:
hi, sorry for my english but i don't speak good english. in this web service i send 2 data stream(xml and xsl file) and i would like to return a xslt trasform-file byte array (now i return string...
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...
1
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...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
1
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.