{"title":"Media.ExportFile(Text) Method","url":"https://jonas-paprotka.de/docs/dev-itpro/developer/methods-auto/media/media-exportfile-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/media/media-exportfile-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/media/media-exportfile-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":"Exports the media object (such as an image) that is currently used on record to a file on your computer or network.","date":"2026-10-01","meta":{"topic":"reference"},"outline":[{"level":1,"title":"Media.ExportFile(Text) Method","slug":"mediaexportfiletext-method","at":0,"chars":2820},{"level":2,"title":"Syntax","slug":"syntax","at":354,"chars":67},{"level":2,"title":"Parameters","slug":"parameters","at":421,"chars":205},{"level":2,"title":"Return Value","slug":"return-value","at":626,"chars":249},{"level":2,"title":"Remarks","slug":"remarks","at":875,"chars":527},{"level":2,"title":"Example","slug":"example","at":1402,"chars":1285},{"level":2,"title":"Related information","slug":"related-information","at":2687,"chars":133}],"text":"# Media.ExportFile(Text) Method\n> Version: _Available or changed with runtime version 1.0._\nExports the media object (such as an image) that is currently used on record to a file on your computer or network. On the record, the media object is referenced in a Media data type field.\n> NOTE\n> This method is supported only in Business Central on-premises.\n## Syntax\n```al\n[Result := ]  Media.ExportFile(Filename: Text)\n```\n## Parameters\nMedia\nType: media-data-type\nAn instance of the media-data-type data type.\nFilename\nType: ../text/text-data-type\nSpecifies the full path and name of the file to create for the exported media.\n## Return Value\n*[Optional] Result*\nType: ../boolean/boolean-data-type\ntrue if the media was successfully exported, otherwise false. If you omit this optional return value and the operation does not execute successfully, a runtime error will occur.\n## Remarks\nThe exported media file will be of the same media type, such as JPEG \\(.jpg\\) or GIF \\(.gif\\), as it was when imported. For more information about the media types, see Supported Media Types<../../devenv-working-with-media-on-records#SupportedMediaTypes>.\nIf a file with the same name as the exported file already exists in the target folder and the current session has write access on the file, the existing file will be automatically replaced by the new file. If the export fails, the existing file will be erased.\n## Example\nThis example uses the ExportFile method to export media objects that are used on records in a sample table that is named My Items. Each media object is exported to a separate file in a folder on your computer.\nThe example assumes that the My Items table already exists. Also, the table contains a Media data type field that is named Image, and one or more records already include media. For information about importing media, see media-importfile-method or media-importstream-instream-text-text-method.\nThe code iterates over records in the My Items table. If a media object is referenced in the Image field, the media is exported to a file in the C:\\images folder. The file is given a name in the format ItemNN.jpg, where NN is the number assigned to item record in the table, as specified by the No. field.\n```al\nvar\n    myItemRec: Record \"My Items\";\n    fileName: Text;\n    count: Integer;\n    Text000: Label '%1 media files were exported';\nbegin\n    if myItemRec.FindFirst() then begin\n        repeat begin\n            fileName := 'C:\\images\\' + 'Item' + Format(myItemRec.\"No.\") + '.jpg';\n            if myItemRec.Image.ExportFile(fileName) then\n                count := count + 1\n        end until myItemRec.Next < 1;\n        Message(Text000, count);\n    end;\nend;\n```\n## Related information\nmedia-data-type\nGet Started with AL<../../devenv-get-started>\nDeveloping Extensions<../../devenv-dev-overview>"}