{"title":"File.Create(Text [, TextEncoding]) Method","url":"https://jonas-paprotka.de/docs/dev-itpro/developer/methods-auto/file/file-create-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-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.","credit":"Microsoft Corporation, CC BY 4.0","origin":"https://learn.microsoft.com/en-us/dynamics365/business-central/dev-itpro/developer/methods-auto/file/file-create-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":"Creates an Automation object.","date":"2026-10-01","meta":{"topic":"reference"},"outline":[{"level":1,"title":"File.Create(Text [, TextEncoding]) Method","slug":"filecreatetext-textencoding-method","at":0,"chars":2037},{"level":2,"title":"Syntax","slug":"syntax","at":206,"chars":156},{"level":2,"title":"Parameters","slug":"parameters","at":362,"chars":260},{"level":2,"title":"Return Value","slug":"return-value","at":622,"chars":238},{"level":2,"title":"Remarks","slug":"remarks","at":860,"chars":466},{"level":2,"title":"Example","slug":"example","at":1326,"chars":579},{"level":2,"title":"Related information","slug":"related-information","at":1905,"chars":132}],"text":"# File.Create(Text [, TextEncoding]) Method\n> Version: _Available or changed with runtime version 1.0._\nCreates an Automation object.\n> NOTE\n> This method is supported only in Business Central on-premises.\n## Syntax\n```al\n[Ok := ]  File.Create(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 the file-textmode-method returns true and you read or write to the file, text is put in the buffer.\nIf the file-textmode-method method returns false, binary information is put in the buffer.\nIf 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.\n## Example\nThe 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.\n```al\n var\n    TestFile: File;\nbegin\n    if TestFile.Create('C:\\TestFolder\\TestFile.txt') then begin\n      Message('%1 is created', TestFile.Name);\n    end else\n    Error('The file could not be created');\nend;\n```\n## Related information\nfile-data-type\nGet Started with AL<../../devenv-get-started>\nDeveloping Extensions<../../devenv-dev-overview>"}