System.IO.FileStream.SetLength Method

Sets the length of this stream to the given value.

Syntax

public override void SetLength (long value)

Parameters

value
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.
ArgumentOutOfRangeException value is less than zero.

Remarks

This method overrides Stream.SetLength(long).

If the given value is less than the current length of the stream, the stream is truncated. If the given 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 undefined.

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

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.

For a list of common file and directory operations, see Common I/O Tasks.

Requirements

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