Sets the position within the current stream to the specified value.
[Visual Basic] Overrides Public Function Seek( _ ByVal offset As Long, _ ByVal loc As SeekOrigin _ ) As Long [C#] public override long Seek( long offset, SeekOrigin loc ); [C++] public: __int64 Seek( __int64 offset, SeekOrigin loc ); [JScript] public override function Seek( offset : long, loc : SeekOrigin ) : long;
- The new position within the stream. This is relative to the loc parameter, and can be positive or negative.
- A value of type SeekOrigin, which acts as the seek reference point.
The new position within the stream, calculated by combining the initial reference point and the offset.
|IOException||Seeking is attempted before the beginning of the stream.|
|ArgumentOutOfRangeException||offset is greater than MaxValue.|
|ArgumentException||There is an invalid SeekOrigin.|
|ObjectDisposedException||The current stream instance is closed.|
For an example of creating a file and writing text to a file, see Writing Text to a File. For an example of reading text from a file, see Reading Text from a File. For an example of reading from and writing to a binary file, see Reading and Writing to a Newly Created Data File.
This method overrides Seek.
Seeking to any location beyond the length of the stream is supported.
[Visual Basic, C#, C++] This code example is part of a larger example provided for the MemoryStream class.
[Visual Basic] ' Set the stream position to the beginning of the stream. memStream.Seek(0, SeekOrigin.Begin) [C#] // Set the position to the beginning of the stream. memStream.Seek(0, SeekOrigin.Begin); [C++] // Set the stream position to the beginning of the stream. memStream->Seek(0, SeekOrigin::Begin);
[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button in the upper-left corner of the page.
Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family, .NET Compact Framework, Common Language Infrastructure (CLI) Standard