web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Small and medium business | Business Central, N...
Suggested Answer

Bulk export item pictures BUsiness central

(0) ShareShare
ReportReport
Posted on by

Hi,

we have business central 15 and I wanted to bulk export items pictures at a time and below is my code. It doesn't download any zip file. 

if ItemCode = '' then
            error('Add item filter');
        MyItem.SetFilter("No.", '%1', ItemCode);
        ZipFileName := 'Picture.zip';
        datacompresion.CreateZipArchive();
        repeat
            with MyItem do begin
                if Picture.Count > 0 then begin
                    ItemCnt := ItemCnt + 1;
                    for Index := 1 to Picture.Count do begin
                        PicCount := PicCount + 1;
                        FileName := '';
                        if TenantMedia.Get(Picture.Item(Index)) then begin
                            TenantMedia.calcfields(Content);
                            if TenantMedia.Content.HasValue then begin
                                FileName := "No." + '-' + format(Index) + GetTenantMediaFileExtension(TenantMedia);
                                TenantMedia.Content.CreateInStream(PicInstream);
                                datacompresion.AddEntry(PicInStream, FileName);                                
                            end;
                        end;
                    end;
                end;
            end;
        until MyItem.Next() = 0;
        Message('Items processed ' + Format(ItemCnt) + ' Pictures processed ' + Format(PicCount));
        blobStorage.CreateOutStream(ZipOutStream);
        datacompresion.SaveZipArchive(ZipOutStream);
        datacompresion.CloseZipArchive();
        blobStorage.CreateInStream(ZipInStream);
        DownloadFromStream(ZipInStream, 'Download zip file', '', '', ZipFileName);
I tried to fix the solution mentioned in the below link, but no zip file is downloaded.
does anyone has any idea why it is not working.
  • Suggested answer
    Binesh Profile Picture
    7,887 on at

    Hello,

    I have tested the below code and it is working fine for me,

    Make sure you have imported the picture in your Item list or for testing purpose just import the pictures for some items and then check

    you can use the below code as it is for your test environment.

    action(ExportPicturesFromCloud)
    {
        ApplicationArea = All;
        Image = ExportAttachment;
        ToolTip = 'Export all the images into Zip';
        trigger OnAction()
        var
            MyItem: Record Item;
            TenantMedia: Record "Tenant Media";
            datacompresion: Codeunit 425;
            blobStorage: Codeunit "Temp Blob";
            PicInStream, ZipInStream : InStream;
            ZipOutStream: OutStream;
            ZipFileName: Text;
            ItemCnt, Index, PicCount : Integer;
    
        begin
            ZipFileName := 'Picture.zip';
            datacompresion.CreateZipArchive();
            MyItem.Reset();
            MyItem.FindSet();
            repeat
                if MyItem.Picture.Count > 0 then begin
                    ItemCnt := ItemCnt   1;
                    for Index := 1 to MyItem.Picture.Count do begin
                        PicCount := PicCount   1;
                        if TenantMedia.Get(MyItem.Picture.Item(Index)) then begin
                            TenantMedia.calcfields(Content);
                            if TenantMedia.Content.HasValue then begin
                                TenantMedia.Content.CreateInStream(PicInstream);
                                datacompresion.AddEntry(PicInStream, MyItem."No."   '.png');
                            end;
                        end;
                    end;
                end;
            until MyItem.Next() = 0;
            Message('Items processed '   Format(ItemCnt)   ' Pictures processed '   Format(PicCount));
            blobStorage.CreateOutStream(ZipOutStream);
            datacompresion.SaveZipArchive(ZipOutStream);
            datacompresion.CloseZipArchive();
            blobStorage.CreateInStream(ZipInStream);
            DownloadFromStream(ZipInStream, 'Download zip file', '', '', ZipFileName);
        end;
    }

    pastedimage1592418816708v1.png

    pastedimage1592418839721v2.png

  • Community Member Profile Picture
    on at

    Sorry for the late reply.

    For some reason above code didn't work for me so I have used exportfile functionality to downloaded pictures to the folder.

    Thank you so much for the support.

  • Binesh Profile Picture
    7,887 on at

    Hi yasmeen,

    If your problem is solved then mark this answer as verify so that other members can be benefited.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Women in Power Builds Momentum

Expanding mentorship, skilling, and AI innovation

Leaderboard > Small and medium business | Business Central, NAV, RMS

#1
OussamaSabbouh Profile Picture

OussamaSabbouh 645 Super User 2026 Season 2

#2
YUN ZHU Profile Picture

YUN ZHU 432 Super User 2026 Season 2

#3
Teagen Boll Profile Picture

Teagen Boll 248 Super User 2026 Season 2

Last 30 days Overall leaderboard

Featured topics

Microsoft Training Manuals

Product updates

Dynamics 365 release plans