SeekOrigin Enumeration
.NET Framework (current version)
Specifies the position in a stream to use for seeking.
Assembly: mscorlib (in mscorlib.dll)
| Member name | Description | |
|---|---|---|
| Begin | Specifies the beginning of a stream. | |
| Current | Specifies the current position within a stream. | |
| End | Specifies the end of a stream. |
SeekOrigin is used by the Seek methods of Stream, BufferedStream, FileStream, MemoryStream, BinaryWriter, and other classes. The Seek methods take an offset parameter that is relative to the position specified by SeekOrigin.
The following example shows how to read backwards starting at the end of the stream, and how to read from a specified point in the stream.
Imports System Imports System.IO Public Class FSSeek Public Shared Sub Main() Dim offset As Long Dim nextByte As Integer ' alphabet.txt contains "abcdefghijklmnopqrstuvwxyz" Using fs As New FileStream("c:\temp\alphabet.txt", FileMode.Open, FileAccess.Read) For offset = 1 To fs.Length fs.Seek(-offset, SeekOrigin.End) Console.Write(Convert.ToChar(fs.ReadByte())) Next offset Console.WriteLine() fs.Seek(20, SeekOrigin.Begin) nextByte = fs.ReadByte() While (nextByte > 0) Console.Write(Convert.ToChar(nextByte)) nextByte = fs.ReadByte() End While Console.WriteLine() End Using End Sub End Class ' This code example displays the following output: ' ' zyxwvutsrqponmlkjihgfedcba ' uvwxyz
Universal Windows Platform
Available since 8
.NET Framework
Available since 1.1
Portable Class Library
Supported in: portable .NET platforms
Silverlight
Available since 2.0
Windows Phone Silverlight
Available since 7.0
Windows Phone
Available since 8.1
Available since 8
.NET Framework
Available since 1.1
Portable Class Library
Supported in: portable .NET platforms
Silverlight
Available since 2.0
Windows Phone Silverlight
Available since 7.0
Windows Phone
Available since 8.1
Show: