FileStream.CanSeek プロパティ
アセンブリ: mscorlib (mscorlib.dll 内)

ストリームがシークをサポートしている場合は true。ストリームが閉じているか、FileStream がパイプまたはコンソールへの出力などのオペレーティング システム ハンドルから構築された場合は false。

Stream から派生したクラスがシークをサポートしていない場合に、Length、SetLength、Position、および Seek を呼び出すと、NotSupportedException がスローされます。

CanSeek プロパティを使用して、ストリームがシークをサポートしているかどうかを確認する例を次に示します。
Imports System Imports System.IO Public Class Test Public Shared Sub Main() Dim path As String = "c:\temp\MyTest.txt" ' Delete the file if it exists. If File.Exists(path) Then File.Delete(path) End If 'Create the file. Dim fs As FileStream = File.Create(path) If fs.CanSeek Then Console.WriteLine("The stream connected to {0} is seekable.", path) Else Console.WriteLine("The stream connected to {0} is not seekable.", path) End If fs.Close() End Sub End Class
using System; using System.IO; using System.Text; class Test { public static void Main() { string path = @"c:\temp\MyTest.txt"; // Delete the file if it exists. if (File.Exists(path)) { File.Delete(path); } //Create the file. 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); } } } }
using namespace System; using namespace System::IO; using namespace System::Text; int main() { String^ path = "c:\\temp\\MyTest.txt"; // Delete the file if it exists. if ( File::Exists( path ) ) { File::Delete( path ); } //Create the file. FileStream^ fs = File::Create( path ); try { 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 ); } } finally { if ( fs ) delete (IDisposable^)fs; } }
import System.*; import System.IO.*; import System.Text.*; class Test { public static void main(String[] args) { String path = "c:\\temp\\MyTest.txt"; // Delete the file if it exists. if (File.Exists(path)) { File.Delete(path); } //Create the file. FileStream fs = File.Create(path); try { if (fs.get_CanSeek()) { Console.WriteLine("The stream connected to {0} " + "is seekable.", path); } else { Console.WriteLine("The stream connected to {0} is not " + " seekable.", path); } } finally { fs.Dispose(); } } //main } //Test

Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


- FileStream.CanSeek プロパティのページへのリンク