{"title":"Media.ExportStream(OutStream) Method","url":"https://jonas-paprotka.de/docs/dev-itpro/developer/methods-auto/media/media-exportstream-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-exportstream-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-exportstream-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 current media object (such as a JPEG image) that is used on record to an OUTSTREAM object.","date":"2026-10-01","meta":{"topic":"reference"},"outline":[{"level":1,"title":"Media.ExportStream(OutStream) Method","slug":"mediaexportstreamoutstream-method","at":0,"chars":2268},{"level":2,"title":"Syntax","slug":"syntax","at":381,"chars":72},{"level":2,"title":"Parameters","slug":"parameters","at":453,"chars":222},{"level":2,"title":"Return Value","slug":"return-value","at":675,"chars":249},{"level":2,"title":"Example","slug":"example","at":924,"chars":1211},{"level":2,"title":"Related information","slug":"related-information","at":2135,"chars":133}],"text":"# Media.ExportStream(OutStream) Method\n> Version: _Available or changed with runtime version 1.0._\nExports the current media object (such as a JPEG image) that is used on record to an OUTSTREAM object. The OUTSTREAM object can be created from a BLOB field, a FILE or from a .NET Framework interoperability object. In the record, the media is referenced in a Media data type field.\n## Syntax\n```al\n[Result := ]  Media.ExportStream(Stream: OutStream)\n```\n## Parameters\nMedia\nType: media-data-type\nAn instance of the media-data-type data type.\nStream\nType: ../outstream/outstream-data-type\nThe OutStream object that is created by the object that will receive the media content.\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## Example\nThis example uses the ExportStream to iterate over a sample table named My Items table and export any media that is used on records to an OutStream that is created on a file object.\nThis example assumes that the My Item table contains a Media data type field that is named Image, and that you have already imported some media on records. For information about importing media, see media-importfile-method or media-importstream-instream-text-text-method.\n```al\n var\n    myItemRec: Record \"My Items\";\n    fileName: Text;\n    count: Integer;\n    exportFile: File;\n    dataOutStream: OutStream;\n    Text000: Label '%1 media files were exported';\nbegin\n    if myItemRec.FindFirst() then begin\n        repeat begin\n            if myItemRec.Image.HasValue then begin\n              fileName := 'C:\\images\\export\\' + 'ItemPictureFromStream' + Format(myItemRec.\"No.\") + '.jpg';\n              exportFile.Create(fileName);\n              exportFile.CreateOutstream(dataOutStream);\n              myItemRec.Image.ExportStream(dataOutStream);\n              count := count + 1;\n              exportFile.Close;\n            end;\n        end until myItemRec.Next < 1;\n        Message(Text000, count);\n    end;\nend;\n\n```\n## Related information\nmedia-data-type\nGet Started with AL<../../devenv-get-started>\nDeveloping Extensions<../../devenv-dev-overview>"}