Hello, I want to share a little code that allows you to import multiple files in a .zip and attach them to a “Sales Order“.
![](https://ivansingleton.dev/wp-content/uploads/2022/08/image.png)
This process could easily be adjusted to any Business Central list that can upload attachments. (In case the list page doesn’t have them, you would have to first create a little customization before using this code).
If we go to the page code “page 1174 “Document Attachment Factbox” we can check which master tables we could attach files to.
Video:
In the following video, I show a set of files that are compressed into a .zip and automatically uncompressed and attached to the attachment list.
Code
Below I show the code that allows the import.
As you can see, it is quite simple.
The code will be divided into 2 parts:
- Pageextension: “Sales Order List”.
- Codeunit: Import.
Pageextension Sales Order List:
This first code is simply a new button that has been added to the “Sales Order List” page, and it will be in charge of invoking the .zip import codeunit
Codetunit Import:
This codeunit will allow us to import a .zip where it will do the following tasks:
- Read and upload the .zip file
- List all contained files.
- Obtain the information of name, the extension of each file, and its content in instream.
- Insert into table “Document Attachment”.
Conclusion
As we could see, it is a simple way to perform an import of multiple files to the list of attachments of a master table, this would undoubtedly save the end user a lot of time in case they constantly work with attachments.
Code on Github
All the code used in this post can be found in this link.
I hope this has been helpful.