Return the contents of a text file as a string.
XSharp.Core (in XSharp.Core.dll) Version: 2.6
Syntax Request Example
cFileName AS STRING
) AS STRING
public static string MemoRead(
- Type: String
The name of the text file to read from disk, including an optional drive, directory, and extension. SetDefault() and SetPath() settings are ignored; the Windows default is used unless you specify a drive and directory as part of the file name. No extension is assumed.
The contents of the file.
The maximum file size that can be read is MAX_ALLOC bytes — the maximum size of a string.
If <cFileName> does not exist, MemoRead() returns a NULL_STRING.
If it exists, this function attempts to open the file in shared mode and, if successful, it proceeds.
If access is denied because, for example, another process has exclusive use of the file, MemoRead() returns a NULL_STRING and NetErr() is set to TRUE.
MemoRead() reads a disk file into memory, where it can be manipulated as a string or assigned to a memo field. MemoRead() is used with MemoEdit() and MemoWrit() to edit an imported disk file; then write it back to disk.
This function does an automatic OEM to ANSI conversion when SetAnsi() is FALSE.
This function should NOT be used to read the contents of a binary file (such as a word document).
Use MemoReadBinary() in stead .
This example uses MemoRead() to assign the contents of a text file to the Notes memo field and to a character variable:
1REPLACE Notes WITH MemoRead("temp.txt")
2cString = MemoRead("temp.txt")
This example defines a function that edits a disk file:
2 LOCAL cString AS STRING
3 If(cString := MemoRead(cFile)) = NULL_STRING
4 ? "Error reading " + cFile
5 RETURN FALSE
7 MemoWrit(cFile, MemoEdit(cString))
8 RETURN TRUE