WRITE Function (File)
Writes to an MS-DOS encoded file or binary file.
Syntax
File.WRITE(Value)
Parameters
File
Type: File
The file to write to.
Value
Type: all simple data types, and records
The data that you want to write to the file.
Remarks
You must call the TEXTMODE Function (File) before you call the WRITE function.
If TEXTMODE Function (File) is set to true and Value is an integer, then the integer is written as text, followed by a new line character.
If Value is a record, each field is separated by a tab character.
If TEXTMODE Function (File) is false and Value is an integer, an integer is written that is four bytes long.
MS-DOS encoding requires a different character set for each language. MS-DOS text is encoded to the internal Unicode data type by using the system locale language of the computer that is running Microsoft Dynamics NAV Server. If you write to a file that uses MS-DOS encoding, then you must set the system locale language of the computer that is running Microsoft Dynamics NAV Server to match the language of the data that you want to write to the file.
We recommend that you use the File data type for files that were created in earlier versions of Dynamics NAV.
To read or write files in Unicode or in other formats, we recommend that you use .NET Framework interoperability and use the System.IO Namespace.
Example
The following example determines whether the specified file exists. If it exists, the WRITEMODE Function (File) allows the file to be open for writing. The OPEN Function (File) opens the file, the WRITE Function (FILE) writes the text “Hello World” to the file and then the CLOSE Function (File) closes the file. If the file does not exist, then an error message is displayed. This example assumes that you have created the following file: C:\TestFolder\TestFile.txt. This example requires that you create the following variables in the C/AL Globals window.
Variable name | DataType |
---|---|
FileName | Text |
TestFile | File |
FileName := 'C:\TestFolder\TestFile.txt';
IF EXISTS(FileName) THEN BEGIN
TestFile.WRITEMODE(TRUE);
TestFile.OPEN(FileName);
TestFile.WRITE('Hello World');
TestFile.CLOSE;
END
ELSE
MESSAGE('%1 does not exit.', FileName);