Click or drag to resize
StreamCopyTo Method (Stream, Int32)
Reads all the bytes from the current stream and writes them to a destination stream, using a specified buffer size.

Namespace: System.IO
Assembly: mscorlib (in mscorlib.dll) Version: 4.0.0.0
Syntax
C#
public void CopyTo(
	Stream destination,
	int bufferSize
)

Parameters

destination
Type: System.IOStream
The stream that will contain the contents of the current stream.
bufferSize
Type: SystemInt32
The size of the buffer. This value must be greater than zero. The default size is 4096.
Exceptions
ExceptionCondition
ArgumentNullExceptiondestination is null.
ArgumentOutOfRangeExceptionbufferSize is negative or zero.
NotSupportedExceptionThe current stream does not support reading.-or-destination does not support writing.
ObjectDisposedExceptionEither the current stream or destination were closed before the CopyTo(Stream) method was called.
IOExceptionAn I/O error occurred.
See Also