Windows apps
Collapse the table of content
Expand the table of content
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

MemoryStream.WriteTo Method

Writes the entire contents of this memory stream to another stream.

[Visual Basic]
Public Overridable Sub WriteTo( _
   ByVal stream As Stream _
public virtual void WriteTo(
 Stream stream
public: virtual void WriteTo(
 Stream* stream
public function WriteTo(
   stream : Stream


The stream to write this memory stream to.


Exception Type Condition
ArgumentNullException stream is a null reference (Nothing in Visual Basic).
ObjectDisposedException The current or target stream is closed.


For an example of creating a file and writing text to a file, see Writing Text to a File. For an example of reading text from a file, see Reading Text from a File. For an example of reading from and writing to a binary file, see Reading and Writing to a Newly Created Data File.

When the current stream is open, this method is equivalent to calling Stream.Write on the underlying buffer of this stream.


Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family, .NET Compact Framework, Common Language Infrastructure (CLI) Standard

See Also

MemoryStream Class | MemoryStream Members | System.IO Namespace | Working with I/O | Reading Text from a File | Writing Text to a File

© 2017 Microsoft