{"title":"File.Open(Text [, TextEncoding]) Method","url":"https://jonas-paprotka.de/docs/dev-itpro/developer/methods-auto/file/file-open-method/","by":"JOP-AL","license":"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.","credit":"Microsoft Corporation, CC BY 4.0","origin":"https://learn.microsoft.com/en-us/dynamics365/business-central/dev-itpro/developer/methods-auto/file/file-open-method","source":{"name":"Business Central developer and IT pro docs","repo":"https://github.com/MicrosoftDocs/dynamics365smb-devitpro-pb","commit":"828b6ee72fcd75755627cd6011f3d20899217ab2","date":"2026-11-19"},"checked":"2026-11-19","description":"Opens an ASCII or binary file.","date":"2026-10-01","meta":{"topic":"reference"},"outline":[{"level":1,"title":"File.Open(Text [, TextEncoding]) Method","slug":"fileopentext-textencoding-method","at":0,"chars":1982},{"level":2,"title":"Syntax","slug":"syntax","at":264,"chars":154},{"level":2,"title":"Parameters","slug":"parameters","at":418,"chars":260},{"level":2,"title":"Return Value","slug":"return-value","at":678,"chars":238},{"level":2,"title":"Remarks","slug":"remarks","at":916,"chars":316},{"level":2,"title":"Example","slug":"example","at":1232,"chars":618},{"level":2,"title":"Related information","slug":"related-information","at":1850,"chars":132}],"text":"# File.Open(Text [, TextEncoding]) Method\n> Version: _Available or changed with runtime version 1.0._\nOpens an ASCII or binary file. This method does not create the file if it does not exist.\n> NOTE\n> This method is supported only in Business Central on-premises.\n## Syntax\n```al\n[Ok := ]  File.Open(Name: Text [, Encoding: TextEncoding])\n```\n> NOTE\n> This method can be invoked without specifying the data type name.\n## Parameters\nFile\nType: file-data-type\nAn instance of the file-data-type data type.\nName\nType: ../text/text-data-type\n*[Optional] Encoding*\nType: ../textencoding/textencoding-option\nThe encoding that will be used by the stream. The default encoding is MSDos.\n## Return Value\n*[Optional] Ok*\nType: ../boolean/boolean-data-type\ntrue 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.\n## Remarks\nIf 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.\n## Example\nThis 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.\n```al\n var\n    TestFile: File;\n```\n```al\nTestFile.TextMode(True);\nTestFile.WriteMode(False);\nTestFile.Open('C:\\temp\\simple.xml');\n```\nIf 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.\n```al\nTestFile.TextMode(True);\nTestFile.WriteMode(False);\nTestFile.Open('C:\\temp\\simple.xml', TextEncoding::Windows);\n```\n## Related information\nfile-data-type\nGet Started with AL<../../devenv-get-started>\nDeveloping Extensions<../../devenv-dev-overview>"}