Partager via


Stream.SetLength Method

Microsoft Silverlight will reach end of support after October 2021. Learn more.

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

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

Syntax

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

Parameters

  • value
    Type: System.Int64
    The desired length of the current stream in bytes.

Exceptions

Exception Condition
IOException

An I/O error occurs.

NotSupportedException

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

ObjectDisposedException

Methods were called after the stream was closed.

Remarks

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

Silverlight

Supported in: 5, 4, 3

Silverlight for Windows Phone

Supported in: Windows Phone OS 7.1, Windows Phone OS 7.0

XNA Framework

Supported in: Xbox 360, Windows Phone OS 7.0

Platforms

For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.

See Also

Reference