Mono Class Library: System.IO.FileStream Overview | Members

System.IO.FileStream.SetLength Method

Sets the length of the current stream to the specified value.

public override void SetLength (long value)

Parameters

value
A long that specifies the new length of the stream.

Exceptions

TypeReason
System.IO.IOException An I/O error occurred.
NotSupportedExceptionThe current stream does not support writing and seeking.
ArgumentOutOfRangeExceptionvalue is less than zero.

Remarks

If value is less than the current length of the stream, the stream is truncated. If value is greater than the current length of the stream, the stream is expanded, and the contents of the stream between the old and the new length are undefined. A stream is required to support both writing and seeking to implement FileStream.SetLength(long).

Note:

Use the FileStream.CanWrite property to determine whether the current instance supports writing, and the FileStream.CanSeek property to determine whether seeking is supported. For additional information, see Stream.CanWrite and Stream.CanSeek .

This method overrides Stream.SetLength(long).

Requirements

Namespace: System.IO
Assembly: mscorlib (in mscorlib.dll)
Assembly Versions: 1.0.5000.0, 2.0.0.0