# 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
```al
[Ok := ]  File.Create(Name: Text [, Encoding: TextEncoding])
```
> NOTE
> This method can be invoked without specifying the data type name.
## Parameters
File
Type: file-data-type
An instance of the file-data-type data type.
Name
Type: ../text/text-data-type
*[Optional] Encoding*
Type: ../textencoding/textencoding-option
The encoding that will be used by the stream. The default encoding is MSDos.
## Return Value
*[Optional] Ok*
Type: ../boolean/boolean-data-type
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 file-textmode-method returns true and you read or write to the file, text is put in the buffer.
If the file-textmode-method 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 file-close-method 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.
```al
 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;
```
## Related information
file-data-type
Get Started with AL<../../devenv-get-started>
Developing Extensions<../../devenv-dev-overview>

Copyright (c) Microsoft Corporation. CC BY 4.0, https://creativecommons.org/licenses/by/4.0/; code samples MIT. From https://learn.microsoft.com/en-us/dynamics365/business-central/dev-itpro/developer/methods-auto/file/file-create-method, MicrosoftDocs/dynamics365smb-devitpro-pb at 828b6ee (2026-11-19). Changed: includes filled in, links to this site, and for agents shortened without dropping a fact. https://jonas-paprotka.de/docs/dev-itpro/developer/methods-auto/file/file-create-method/
