Editar

Compartir a través de


File.Open(Text [, TextEncoding]) Method

Version: Available or changed with runtime version 1.0.

Opens an ASCII or binary file. This method does not create the file if it does not exist.

Note

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

Syntax

[Ok := ]  File.Open(Name: Text [, Encoding: TextEncoding])

Note

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

Parameters

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

Name
 Type: Text

[Optional] Encoding
 Type: TextEncoding
The encoding that will be used by the stream. The default encoding is MSDos.

Return Value

[Optional] Ok
 Type: Boolean
true if the operation was successful; otherwise false. If you omit this optional return value and the operation does not execute successfully, a runtime error will occur.

Remarks

If you call Open on a file variable that refers to an open file, then the method does not automatically close the existing file and open the new file. You must explicitly call the Close Method (File) to close the existing file. If you call Open on a file that is already open, then a run-time error occurs.

Example

This example shows how to open an .xml file for reading in text mode. To use this example, you must create the simple.xml file at C:\temp and create the following variable.

 var
    TestFile: File;
TestFile.TextMode(True);  
TestFile.WriteMode(False);  
TestFile.Open('C:\temp\simple.xml');  

If you want to be explicit about the encoding of a file, you can set the TextEncoding parameter. The following code example replaces the last statement in the previous example.

TestFile.TextMode(True);  
TestFile.WriteMode(False);  
TestFile.Open('C:\temp\simple.xml', TextEncoding::Windows);  

File Data Type
Get Started with AL
Developing Extensions