{"title":"File.Trunc() Method","url":"https://jonas-paprotka.de/docs/dev-itpro/developer/methods-auto/file/file-trunc-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-trunc-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-trunc-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":"Truncate an ASCII or binary file to the current position of the file pointer.","date":"2026-10-01","meta":{"topic":"reference"},"outline":[{"level":2,"title":"Syntax","slug":"syntax","at":210,"chars":109},{"level":2,"title":"Parameters","slug":"parameters","at":319,"chars":85},{"level":2,"title":"Remarks","slug":"remarks","at":404,"chars":184},{"level":2,"title":"Example","slug":"example","at":588,"chars":667},{"level":2,"title":"Related information","slug":"related-information","at":1255,"chars":132}],"text":"> Version: _Available or changed with runtime version 1.0._\nTruncate an ASCII or binary file to the current position of the file pointer.\n> NOTE\n> This method is supported only in Business Central on-premises.\n## Syntax\n```al\n File.Trunc()\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\nTypically, you use this method together with file-seek-method. Use File.Seek to position the pointer in the file and then use File.Trunc to truncate the file at that point.\n## Example\nThe following example sets a pointer at position 20 in a file and truncates the file at the pointer position. The file-writemode-method allows the file that is named C:\\\\TestFolder\\\\TestFile.txt to open in write mode. The Seek method sets a pointer at position 20 in the file and then the file-trunc-method truncates the contents at the pointer position. This example assumes that you have created a text file named C:\\\\TestFolder\\\\TestFile.txt. The file is then saved a truncated file.\n```al\n var\n    TestFile: File;\nbegin\n    TestFile.WriteMode(True);\n    TestFile.Open('C:\\TestFolder\\TestFile.txt');\n    TestFile.Seek(20);\n    TestFile.Trunc;\nend;\n\n```\n## Related information\nfile-data-type\nGet Started with AL<../../devenv-get-started>\nDeveloping Extensions<../../devenv-dev-overview>"}