The AL developer preview is still evolving with frequent updates. Follow us on the Dynamics NAV Team Blog for the announcements.
WRITE Method (File)
Writes to an MS-DOS encoded file or binary file.
The file to write to.
Type: all simple data types, and records
The data that you want to write to the file.
You must call the TEXTMODE Method (File) before you call the WRITE method.
If TEXTMODE Method (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 Method (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 Dynamics 365 for Financials service. 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 Dynamics 365 for Financials service 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 365.
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.
The following example determines whether the specified file exists. If it exists, the WRITEMODE Method (File) allows the file to be open for writing. The OPEN Method (File) opens the file, the WRITE Method (FILE) writes the text “Hello World” to the file and then the CLOSE Method (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 global variables.
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);