This documentation is archived and is not being maintained.

BufferedStream.CanSeek Property

Gets a value indicating whether the current stream supports seeking.

[Visual Basic]
Overrides Public ReadOnly Property CanSeek As Boolean
[C#]
public override bool CanSeek {get;}
[C++]
public: __property bool get_CanSeek();
[JScript]
public override function get CanSeek() : Boolean;

Property Value

true if the stream supports seeking; false if the stream is closed or if the stream was constructed from an operating-system handle such as a pipe or output to the console.

Remarks

For an example of creating a file and writing text to a file, see Writing Text to a File. For an example of reading text from a file, see Reading Text from a File. For an example of reading from and writing to a binary file, see Reading and Writing to a Newly Created Data File.

If a class derived from Stream does not support seeking, calls to Length, SetLength, Position, and Seek throw a NotSupportedException.

If the stream is closed, this property returns false.

Example

[Visual Basic, C#, C++] This code example is part of a larger example provided for the BufferedStream class.

[Visual Basic] 
' Check whether the underlying stream supports seeking.
If bufStream.CanSeek Then
    Console.WriteLine("NetworkStream supports" & _
        "seeking." & vbCrLf)
Else
    Console.WriteLine("NetworkStream does not " & _
        "support seeking." & vbCrLf)
End If

[C#] 
// Check whether the underlying stream supports seeking.
Console.WriteLine("NetworkStream {0} seeking.\n",
    bufStream.CanSeek ? "supports" : "does not support");

[C++] 
// Check whether the underlying stream supports seeking.
Console::WriteLine(S"NetworkStream {0} seeking.\n",
    bufStream->CanSeek ? S"supports" : S"does not support");

[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter in the upper-left corner of the page.

Requirements

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family

See Also

BufferedStream Class | BufferedStream Members | System.IO Namespace | SetLength | Seek | Working with I/O | Reading Text from a File | Writing Text to a File

Show: