Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All

SeekOrigin Enumeration

Specifies the position in a stream to use for seeking.

Namespace:  System.IO
Assemblies:   System.IO (in System.IO.dll)
  mscorlib (in mscorlib.dll)

Public Enumeration SeekOrigin

Member nameDescription
Supported by the XNA FrameworkSupported by Portable Class LibraryBeginSpecifies the beginning of a stream.
Supported by the XNA FrameworkSupported by Portable Class LibraryCurrentSpecifies the current position within a stream.
Supported by the XNA FrameworkSupported by Portable Class LibraryEndSpecifies 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)
            Next offset

            fs.Seek(20, SeekOrigin.Begin)

            nextByte = fs.ReadByte()
            While (nextByte > 0)
                nextByte = fs.ReadByte()
            End While

        End Using 
    End Sub 
End Class 

' This code example displays the following output: 

' zyxwvutsrqponmlkjihgfedcba 
' uvwxyz

.NET Framework

Supported in: 4.6, 4.5, 4, 3.5, 3.0, 2.0, 1.1

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

XNA Framework

Supported in: 3.0, 2.0, 1.0

.NET for Windows Phone apps

Supported in: Windows Phone 8.1, Windows Phone Silverlight 8.1, Windows Phone Silverlight 8

Portable Class Library

Supported in: Portable Class Library
© 2015 Microsoft