C# FileStream CanSeek

Description

FileStream CanSeek Gets a value indicating whether the current stream supports seeking.

Syntax

FileStream.CanSeek has the following syntax.


public override bool CanSeek { get; }

Example

The following example uses the CanSeek property to check whether a stream supports seeking.


/*  w  ww.ja  va2s  . co m*/
using System;
using System.IO;
using System.Text;

class Test 
{
    public static void Main() 
    {
        string path = "MyTest.txt";
        using (FileStream fs = File.Create(path)) 
        {
            if (fs.CanSeek) 
            {
                Console.WriteLine("The stream connected to {0} is seekable.", path);
            } 
            else 
            {
                Console.WriteLine("The stream connected to {0} is not seekable.", path);
            }
        }
    }
}

The code above generates the following result.





















Home »
  C# Tutorial »
    System.IO »




BinaryReader
BinaryWriter
Directory
DirectoryInfo
DriveInfo
File
FileInfo
FileStream
MemoryStream
Path
StreamReader
StreamWriter
StringReader
StringWriter