SeekOrigin Enumeration
Specifies the position in a stream to use for seeking.
Namespace: System.IO
Assembly: mscorlib (in mscorlib.dll)
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.
using System; using System.IO; public class FSSeek { public static void Main() { long offset; int nextByte; // alphabet.txt contains "abcdefghijklmnopqrstuvwxyz" using (FileStream fs = new FileStream(@"c:\temp\alphabet.txt", FileMode.Open, FileAccess.Read)) { for (offset = 1; offset <= fs.Length; offset++) { fs.Seek(-offset, SeekOrigin.End); Console.Write(Convert.ToChar(fs.ReadByte())); } Console.WriteLine(); fs.Seek(20, SeekOrigin.Begin); while ((nextByte = fs.ReadByte()) > 0) { Console.Write(Convert.ToChar(nextByte)); } Console.WriteLine(); } } } // This code example displays the following output: // // zyxwvutsrqponmlkjihgfedcba // uvwxyz
Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)
The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.


