Modifier

Partager via


Media.ExportFile(Text) Method

Version: Available or changed with runtime version 1.0.

Exports 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.

Note

This method is supported only in Business Central on-premises.

Syntax

[Result := ]  Media.ExportFile(Filename: Text)

Parameters

Media
 Type: Media
An instance of the Media data type.

Filename
 Type: Text
Specifies the full path and name of the file to create for the exported media.

Return Value

[Optional] Result
 Type: Boolean
true 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.

Remarks

The 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.

If 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.

Example

This 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.

The 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 ImportFile Method (Media) or ImportStream Method (Media).

The 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.

var
    myItemRec: Record "My Items";
    fileName: Text;
    count: Integer;
    Text000: Label '%1 media files were exported';
begin
    if myItemRec.FindFirst() then begin
        repeat begin 
            fileName := 'C:\images\' + 'Item' + Format(myItemRec."No.") + '.jpg';  
            if myItemRec.Image.ExportFile(fileName) then
                count := count + 1
        end until myItemRec.Next < 1;
        Message(Text000, count);  
    end;
end;

Media Data Type
Get Started with AL
Developing Extensions