.NET Framework Class Library
FileStream..::.Position Property

Gets or sets the current position of this stream.

Namespace:  System.IO
Assembly:  mscorlib (in mscorlib.dll)
Syntax

Visual Basic (Declaration)
Public Overrides Property Position As Long
Visual Basic (Usage)
Dim instance As FileStream
Dim value As Long

value = instance.Position

instance.Position = value
C#
public override long Position { get; set; }
Visual C++
public:
virtual property long long Position {
    long long get () override;
    void set (long long value) override;
}
JScript
public override function get Position () : long
public override function set Position (value : long)

Property Value

Type: System..::.Int64
The current position of this stream.
Exceptions

ExceptionCondition
NotSupportedException

The stream does not support seeking.

IOException

An I/O error occurs.

- or -

The position was set to a very large value beyond the end of the stream in Windows 98 or earlier.

ArgumentOutOfRangeException

Attempted to set the position to a negative value.

EndOfStreamException

Attempted seeking past the end of a stream that does not support this.

Remarks

Seeking to any location beyond the length of the stream is supported. When you seek beyond the length of the file, the file size grows. In Microsoft Windows NT and newer, any data added to the end of the file is set to zero. In Microsoft Windows 98 or earlier, any data added to the end of the file is not set to zero, which means that previously deleted data is visible to the stream. Setting the position of the stream to a large value beyond the end of the stream in Windows 98 or earlier may result in an exception being raised.

For a list of common I/O tasks, see Common I/O Tasks.

Examples

The following example uses the Length and Position properties to check for an end-of-file condition.

Visual Basic
If s.Length = s.Position Then
    Console.WriteLine("End of file has been reached.")
End If
C#
if( s.Length==s.Position )
{
   Console.WriteLine("End of file has been reached.");
}
Visual C++
if ( s->Length == s->Position )
{
   Console::WriteLine( "End of file has been reached." );
}
JScript
if( s.Length==s.Position )
    Console.WriteLine("End of file has been reached.");
Platforms

Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98, Windows CE, Windows Mobile for Smartphone, Windows Mobile for Pocket PC, Xbox 360, Zune

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
Version Information

.NET Framework

Supported in: 3.5, 3.0, 2.0, 1.1, 1.0

.NET Compact Framework

Supported in: 3.5, 2.0, 1.0

XNA Framework

Supported in: 3.0, 2.0, 1.0
See Also

Reference

Other Resources

Tags :


Page view tracker