{"title":"File.Close() Method","url":"https://jonas-paprotka.de/docs/dev-itpro/developer/methods-auto/file/file-close-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-close-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-close-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":"Closes a file that has been opened by the OPEN method (File).","date":"2026-10-01","meta":{"topic":"reference"},"outline":[{"level":2,"title":"Syntax","slug":"syntax","at":194,"chars":109},{"level":2,"title":"Parameters","slug":"parameters","at":303,"chars":85},{"level":2,"title":"Remarks","slug":"remarks","at":388,"chars":65},{"level":2,"title":"Example","slug":"example","at":453,"chars":787},{"level":2,"title":"Related information","slug":"related-information","at":1240,"chars":132}],"text":"> Version: _Available or changed with runtime version 1.0._\nCloses a file that has been opened by the OPEN method (File).\n> NOTE\n> This method is supported only in Business Central on-premises.\n## Syntax\n```al\n File.Close()\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.\n## Remarks\nIf the file is not open, a run-time error will occur.\n## Example\nThe following example determines whether the specified file exists. If it exists, the file-writemode-method allows the file to be open for writing. The file-open-method opens the file, the file-writemode-method writes the text \"Hello World\" to the file, and then the Close method closes the file. If the file does not exist, an error message is displayed. This example assumes that you have created the following file C:\\\\TestFolder\\\\TestFile2.txt.\n```al\nvar\n    FileName: Text;\n    TestFile: File;\nbegin\n    FileName := 'C:\\TestFolder\\TestFile2.txt';\n    if Exists(FileName) then begin\n      TestFile.WriteMode(true);\n      TestFile.Open(FileName);\n      TestFile.Write('Hello World');\n      TestFile.Close;\n    end else\n    Message('%1 does not exist.', FileName);\nend;\n```\n## Related information\nfile-data-type\nGet Started with AL<../../devenv-get-started>\nDeveloping Extensions<../../devenv-dev-overview>"}