Hi, Readers.
Today I would like to talk about a question I was asked recently, how to export all item pictures.
As you might know, you can import multiple item pictures in one go in Business Central. Simply name your picture files with names corresponding to your item numbers, compress them to a zip file, and then use the Import Item Pictures page to manage which item pictures to import. More details: Import Multiple Item Pictures
But what if you want to export all the item pictures? As of now, there is no standard function to do this, and you can only export them one by one.

So we can only consider customization. For example, save the pictures into a zip file, then download it.
We have discussed similar requirements before, and this time is no exception. You can also refer to previous practices.
- Dynamics 365 Business Central: FileManagement.BLOBExport only save last file? -> Adding multiple files into a zip file
- Dynamics 365 Business Central: How to bulk export/download attachments (Downloading multiple attachments via zip file) – Customization
- Dynamics 365 Business Central: Bulk export/download reports with different layouts to a zip file (Download Posted Sales Invoices/Posted Purchase Invoices to a zip file)
Let’s simulate this requirement.
Add two actions, one to export all pictures, and one to export pictures of selected items.



Test video:
Source Code: GitHub (Please note that the source code is for reference only, you can improve it according to your own needs)
pageextension 50100 ItemListExt extends "Item List"
{
actions
{
addafter(AdjustInventory)
{
action(ExportAllItemPictures)
{
Caption = 'Export All Item Pictures';
ApplicationArea = All;
Promoted = true;
PromotedCategory = Process;
PromotedIsBig = true;
Image = Export;
trigger OnAction()
var
Item: Record Item;
begin
Item.Reset();
ExportItemPictures(Item);
end;
}
action(ExportSelectedItemPictures)
{
Caption = 'Export Selected Item Pictures';
ApplicationArea = All;
Promoted = true;
PromotedCategory = Process;
PromotedIsBig = true;
Image = Export;
trigger OnAction()
var
Item: Record Item;
begin
Item.Reset();
CurrPage.SetSelectionFilter(Item);
if not Item.IsEmpty then
ExportItemPictures(Item);
end;
}
}
}
local procedure ExportItemPictures(var Item: Record Item)
var
TempBlob: Codeunit "Temp Blob";
ItemPictureInStream: InStream;
ZipOutStream: OutStream;
ZipInStream: InStream;
DataCompression: Codeunit "Data Compression";
ZipFileName: Text[50];
ItemTenantMedia: Record "Tenant Media";
FileName: Text;
FileExtension: List of [Text];
begin
ZipFileName := 'ItemPictures_' + Format(CurrentDateTime) + '.zip';
DataCompression.CreateZipArchive();
if Item.FindSet() then
repeat
if Item.Picture.Count > 0 then begin
ItemTenantMedia.Get(Item.Picture.Item(1));
ItemTenantMedia.CalcFields(Content);
ItemTenantMedia.Content.CreateInStream(ItemPictureInStream, TextEncoding::UTF8);
FileExtension := ItemTenantMedia."Mime Type".Split('/');
FileName := Item."No." + '.' + FileExtension.Get(2);
DataCompression.AddEntry(ItemPictureInStream, FileName);
end;
until Item.Next() = 0;
TempBlob.CreateOutStream(ZipOutStream);
DataCompression.SaveZipArchive(ZipOutStream);
TempBlob.CreateInStream(ZipInStream);
DownloadFromStream(ZipInStream, '', '', '', ZipFileName);
end;
}
Give it a try!!!😁
END
Hope this will help.
Thanks for reading.
コメント