File.Read(var Any) Method

Version: Available or changed with runtime version 1.0.

Reads from an MS-DOS encoded file or binary file.

Note

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

Syntax

[Read := ]  File.Read(var Read: Any)

Note

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

Parameters

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

Read
 Type: Any
Streams a BigText object that is stored as a BLOB in a table to a BigText variable.

Return Value

[Optional] Read
 Type: Integer
If you omit this optional return value and the operation does not execute successfully, a runtime error will occur.

Remarks

To read from a file that is larger than 1024 bytes, use streams instead of the File.Read method.

MS-DOS encoding, which is also referred to as OEM encoding, is an older format than UTF-8 and UTF-16, but it is still widely supported. MS-DOS encoding was the only format that was supported by earlier versions of Dynamics 365.

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 read 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 in the file that is being read. For example, if the file contains text in Danish, then you must set the system locale language of the computer that is running Dynamics 365 Business Central service to Danish before you call the Read method (File) or Write Method (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 opens a text file that is named C:\TestFolder\TestFile.txt. The READ method read the contents of the file and stores it in the String variable. The method returns the size of the text that was read, stores it in the varSize variable, and displays it in a message box. This example assumes that you have created a text file named C:\TestFolder\TestFile.txt that contains less than 500 bytes.

 var
    Testfile: File;
    String: Text[500];
    varSize: Integer;
begin
    TestFile.Open('C:\TestFolder\TestFile.txt');  
    varSize := TestFile.Read(String);  
    Message('The text "%1" is %2 bytes.', String, varSize);  
end;

See Also

File Data Type
Get Started with AL
Developing Extensions