FileStream.Position FileStream.Position FileStream.Position FileStream.Position Property

Definition

Gets or sets the current position of this stream.

public:
 virtual property long Position { long get(); void set(long value); };
public override long Position { get; set; }
member this.Position : int64 with get, set
Public Overrides Property Position As Long
Property Value

The current position of this stream.

Exceptions

An I/O error occurred.

- or -

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

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

Examples

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

if ( s->Length == s->Position )
{
   Console::WriteLine( "End of file has been reached." );
}
if( s.Length==s.Position )
{
   Console.WriteLine("End of file has been reached.");
}
If s.Length = s.Position Then
    Console.WriteLine("End of file has been reached.")
End If

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 file and directory operations, see Common I/O Tasks.

Applies to

See Also