In our years ( ASI LLC ) developing solutions within the Acumatica framework we have experienced multiple instances in which files of one type or another need to be generated and manipulated within the system.
An example usage which we will review in this article is the archiving of files attached to a document within an Acumatica instance -or- the attachment of files from within a .Zip file to a document within an Acumatica instance.
.Zip – PX.Common.Std
To utilize .ZIP files within Acumatica you will need to add reference to the PX.Common.Std .dll within your project. This .dll can be found in the bin folder of the instance install.
This static method returns an instance of ZipArchive which represents a .ZIP file. This method will take Stream os and bool onlyRead as parameters.
The code example below illustrates the creation of a new zip file utilizing a new MemoryStream and setting the onlyRead argument as false to allow the addition of files to our created .Zip file.
CreateFrom is also utilized when opening a pre-existing .ZIP file. To open a pre-existing file you must first retrieve its byte and create a new MemoryStream from the data, setting the bool onlyRead parameter as true.
This public void method adds a file from the given name and a byte array of the file to be included in the .Zip file.
This method returns a list of files within the .Zip archive; each file’s information is encapsulated within the inner ItemInfo class.
This method is utilized when you only wish to pull the files from a specific directory within the archive. It utilizes the string parameter directory.
This method returns a Stream from a file within the archive. The file is specified by providing a file name, this name
Below you will find examples of creating a new .Zip archive within Acumatica as well as taking a .Zip file attached to a document and reading / saving the contents within.
The following example will retrieve the list of files attached to an Acumatica document and create a .Zip archive which is then attached.
The following example will retrieve the .Zip file attached to an Acumatica document and attach all documents within that archive to the source document.
With the usage of Libraries provided within an Acumatica ERP install, we are able to create and manipulate .Zip files