Stream.SetLength Method

[ This article is for Windows Phone 8 developers. If you’re developing for Windows 10, see the latest documentation. ]

When overridden in a derived class, sets the length of the current stream.

Namespace: System.IO
Assembly: mscorlib (in mscorlib.dll)


Public MustOverride Sub SetLength ( _
    value As Long _
public abstract void SetLength(
    long value



Exception Condition

An I/O error occurs.


The stream does not support both writing and seeking, such as if the stream is constructed from a pipe or console output.


Methods were called after the stream was closed.


If the specified value is less than the current length of the stream, the stream is truncated. If the specified value is larger than the current length of the stream, the stream is expanded. If the stream is expanded, the contents of the stream between the old and the new length are not defined.

A stream must support both writing and seeking for SetLength to work.

Use the CanWrite property to determine whether the current instance supports writing, and the CanSeek property to determine whether seeking is supported.

Version Information

Windows Phone OS

Supported in: 8.1, 8.0, 7.1, 7.0


Windows Phone

See Also


Stream Class

System.IO Namespace