Visual FoxPro Toolkit for .NET

FSeek() Method

Positions the position of the pointer to a specific location in the FileStream

Positions the position of the pointer to a specific location in the FileStream. This one receives a relative position as a third parameter

[VisualBasic]

Public Shared Function FSeek(ByRef oFileStream As FileStream, ByVal nBytesMoved As Integer) As Long
Public Shared Function FSeek(ByRef oFileStream As FileStream, ByVal nBytesMoved As Integer, ByVal nRelativePosition As Integer) As Long

[C#]

public static long FSeek(ref FileStream oFileStream, int nBytesMoved)
public static long FSeek(ref FileStream oFileStream, int nBytesMoved, int nRelativePosition)

Example

[VisualBasic]

Dim nSize As Integer

Dim cString As String

Dim gnFileHandle As System.IO.FileStream

gnFileHandle = FOpen("errors.txt")

'Seek to end of file to determine the number of bytes in the file

nSize = FSeek(gnFileHandle, 0, 2) ' Move pointer to EOF

If nSize <= 0 Then

' If the file is empty, display an error message

Else

FSeek(gnFileHandle, 0, 0) ' Move pointer to BOF

cString = FRead(gnFileHandle, nSize) 'Read the contents

Console.WriteLine(cString) 'Write the string

End If

FClose(gnFileHandle) ' Close the file

Implementation

[VisualBasic]

Public Shared Function FSeek(ByRef oFileStream As FileStream, ByVal nBytesMoved As Integer) As Long
Return oFileStream.Seek(nBytesMoved, 0)
End Function
Public Shared Function FSeek(ByRef oFileStream As FileStream, ByVal nBytesMoved As Integer, ByVal nRelativePosition As Integer) As Long
If nRelativePosition = 2 Then
Return oFileStream.Seek(nBytesMoved, System.IO.SeekOrigin.End)
ElseIf nRelativePosition = 0 Then
Return oFileStream.Seek(nBytesMoved, System.IO.SeekOrigin.Begin)
Else
Return oFileStream.Seek(nBytesMoved, System.IO.SeekOrigin.Current)
End If
End Function

[C#]

public static long FSeek(ref FileStream oFileStream, int nBytesMoved)
{
return oFileStream.Seek(nBytesMoved,0);
}
public static long FSeek(ref FileStream oFileStream, int nBytesMoved, int nRelativePosition)
{
if (nRelativePosition == 2)
{
return oFileStream.Seek(nBytesMoved, System.IO.SeekOrigin.End);
}
else if (nRelativePosition == 0)
{
return oFileStream.Seek(nBytesMoved, System.IO.SeekOrigin.Begin);
}
else
{
return oFileStream.Seek(nBytesMoved, System.IO.SeekOrigin.Current);
}
}

Requirements

Namespace:VFPToolkit

Class:VFPToolkit.files

Platforms:Windows98, WindowsNT4.0, WindowsMillenniumEdition, Windows2000, WindowsXPHomeEdition, WindowsXPProfessional, Windows.NETServerfamily

Assembly:VFPToolkit (in VFPToolkitNET.dll)

See Also

VFPToolkit.files Members | VFPToolkit Namespace