System.IO.FileStream.Seek Method

Sets the current position of this stream to the given value.

Syntax

public override long Seek (long offset, SeekOrigin origin)

Parameters

offset
The point relative to origin from which to begin seeking.
origin
Specifies the beginning, the end, or the current position as a reference point for offset, using a value of type System.IO.SeekOrigin.

Returns

The new position in the stream.

Exceptions

TypeReason
System.IO.IOExceptionAn I/O error occurred.
NotSupportedExceptionThe stream does not support seeking.
ArgumentExceptionAttempted seeking before the beginning of the stream or to more than one byte past the end of the stream.
ObjectDisposedExceptionThe current stream is closed.

Remarks

This method overrides Stream.Seek(long, SeekOrigin).

Note:

Use the FileStream.CanSeek property to determine whether the current instance supports seeking. For additional information, see Stream.CanSeek.

You can seek to any location beyond the length of the stream. When you seek beyond the length of the file, the file size grows. In Windows NT and later versions, data added to the end of the file is set to zero. In Windows 98 or earlier versions, data added to the end of the file is not set to zero, which means that previously deleted data is visible to the stream.

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