Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

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

Import Zip File

(0) ShareShare
ReportReport
Posted on by 115

Hello

Is it possible to import a zip file into Business Central Saas, I need to import some xml Invoice files from a Zip. I know its possible onPrem.

Categories:
  • Suggested answer
    Binesh Profile Picture
    7,885 on at
    RE: Import Zip File

    Hello,

    You can import zip file, for reference see the below code.

    action(ImportZipFile)
        {
            ApplicationArea = All;
            ToolTip = 'Import the images from Zip';
            
            trigger OnAction()
            var
                FileMgt: Codeunit "File Management";
                DataCompression: Codeunit "Data Compression";
                TempBlob: Codeunit "Temp Blob";
                EntryList: List of [Text];
                EntryListKey, ZipFileName, FileName, FileExtension : Text;
                ZipInStream, EntryInStream : InStream;
                EntryOutStream: OutStream;
                Length: Integer;
                SelectZIPFileMsg: Label 'Select the Zip File', Locked = true;
            begin
                if not UploadIntoStream(SelectZIPFileMsg, '', 'Zip Files|*.zip', ZipFileName, ZipInStream) then
                    Error('');
    
                DataCompression.OpenZipArchive(ZipInStream, false);
                DataCompression.GetEntryList(EntryList);
                foreach EntryListKey in EntryList do begin
                    FileName := CopyStr(FileMgt.GetFileNameWithoutExtension(EntryListKey), 1, MaxStrLen(FileName));
                    FileExtension := CopyStr(FileMgt.GetExtension(EntryListKey), 1, MaxStrLen(FileExtension));
    
                    TempBlob.CreateOutStream(EntryOutStream);
                    DataCompression.ExtractEntry(EntryListKey, EntryOutStream, Length);
                    TempBlob.CreateInStream(EntryInStream);
                    //Write your code for importing each file for eg.
                    Image.ImportStream(EntryInStream, FileName);
                end;
            end;
        }

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

Dynamics 365 Community Update – Sep 16th

Welcome to the next edition of the Community Platform Update. This is a weekly…

Announcing Our 2024 Season 2 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Dynamics 365 Community Newsletter - September 2024

Check out the latest community news

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

Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans