# 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
```al
[Ok := ]  File.Open(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 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 file-close-method 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.
```al
 var
    TestFile: File;
```
```al
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.
```al
TestFile.TextMode(True);
TestFile.WriteMode(False);
TestFile.Open('C:\temp\simple.xml', TextEncoding::Windows);
```
## 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-open-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-open-method/
