FWrite() Method



|Visual FoxPro Toolkit for .NET | |

FWrite() Method

Receives a FileStream and string as parameters and writes a string to a FileStream

[pic]

[Visual Basic]

Public Shared Function FWrite(ByRef oFileStream As FileStream, ByVal cString As String) As Integer

Public Shared Function FWrite(ByRef oFileStream As FileStream, ByVal cString As String, ByVal nCharactersWritten As Integer) As Integer

[C#]

public static int FWrite(ref FileStream oFileStream, string cString)

public static int FWrite(ref FileStream oFileStream, string cString, int nCharactersWritten)

Example

[Visual Basic]

'Open an existing file and writes the first 10 characters

Dim goErrFile As System.IO.FileStream

goErrFile = FOpen("errors.txt")

FWrite(goErrFile, "1234567890kamal", 10)

FClose(goErrFile)

Implementation

[Visual Basic]

Public Shared Function FWrite(ByRef oFileStream As FileStream, ByVal cString As String) As Integer

Return VFPToolkit.files.FWrite(oFileStream, cString, cString.Length)

End Function

Public Shared Function FWrite(ByRef oFileStream As FileStream, ByVal cString As String, ByVal nCharactersWritten As Integer) As Integer

Dim i As Integer

'Move the position to the end of the file

'oFileStream.Position = oFileStream.Length;

If cString.Length < nCharactersWritten Then

nCharactersWritten = cString.Length

End If

'Convert the string into an array of bytes

Dim aBytes() As Byte = New Byte(nCharactersWritten) {}

For i = 0 To nCharactersWritten - 1 Step i + 1

aBytes(i) = AscW(cString.Chars(i))

Next

'Call the write method of the FileStream

oFileStream.Write(aBytes, 0, nCharactersWritten)

Return cString.Length

End Function

[C#]

public static int FWrite(ref FileStream oFileStream, string cString)

{

return VFPToolkit.files.FWrite(ref oFileStream, cString, cString.Length);

}

public static int FWrite(ref FileStream oFileStream, string cString, int nCharactersWritten)

{

int i;

//Move the position to the end of the file

//oFileStream.Position = oFileStream.Length;

if(cString.Length < nCharactersWritten)

nCharactersWritten = cString.Length;

//Convert the string into an array of bytes

byte[] aBytes = new byte[nCharactersWritten];

for (i= 0; i < nCharactersWritten ; i++)

{

aBytes[i] = (byte)cString[i];

}

//Call the write method of the FileStream

oFileStream.Write(aBytes, 0, nCharactersWritten);

return cString.Length;

}

Requirements

Namespace: VFPToolkit

Class: VFPToolkit.files

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

Assembly: VFPToolkit (in VFPToolkitNET.dll)

See Also

VFPToolkit.files Members | VFPToolkit Namespace

................
................

In order to avoid copyright disputes, this page is only a partial summary.

Google Online Preview   Download

To fulfill the demand for quickly locating and searching documents.

It is intelligent file search solution for home and business.

Literature Lottery

Related searches