Muokkaa

Jaa


File.Create(Text [, TextEncoding]) Method

Version: Available or changed with runtime version 1.0.

Creates an Automation object.

Note

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

Syntax

[Ok := ]  File.Create(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 the TextMode Method (File) returns true and you read or write to the file, text is put in the buffer.

If the TextMode Method (File) method returns false, binary information is put in the buffer.

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

Example

The following example creates a file that is named TestFile.txt in the path C:\TestFolder\. The TestFile variable stores the file and path that is created. If the file is created, a message that states that the file is created is displayed. Otherwise, an error message is displayed. This example requires that you create the following global variable.

 var
    TestFile: File;
begin
    if TestFile.Create('C:\TestFolder\TestFile.txt') then begin  
      Message('%1 is created', TestFile.Name);  
    end else  
    Error('The file could not be created');  
end;

File Data Type
Get Started with AL
Developing Extensions