Editar

Partilhar via


File.Write(Guid) Method

Version: Available or changed with runtime version 1.0.

Writes to an MS-DOS encoded file or binary file.

Note

This method is supported only in Business Central on-premises.

Syntax

 File.Write(Value: Guid)

Note

This method can be invoked without specifying the data type name.

Parameters

File
 Type: File
An instance of the File data type.

Value
 Type: Guid
The data that you want to write to the file.

Remarks

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 Business Central 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 Business Central 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.

Example

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.

var
    FileName: Text;
    TestFile: File;
    Guid1: GUID;
begin
    FileName := 'C:\TestFolder\TestFile.txt';  
    if Exists(FileName) then begin
      TestFile.WriteMode(True);  
      TestFile.Open(FileName);  
      TestFile.Write(Guid1);  
      TestFile.Close;  
    end else 
      Message('%1 does not exit.', FileName);
end;

File Data Type
Get Started with AL
Developing Extensions