Zipping folders and files within NAV
Zipping files or folders by code is not a common task; nevertheless, let's see how we can do it!
How to do it...
Create a new codeunit from Object Designer.
Add the following global variables:
Name
Type
Subtype
ZipFile
File
MSShell
Automation
'Microsoft Shell Controls And Automation'.Shell
ZipFolder
Automation
'Microsoft Shell Controls And Automation'.Folder
Write the following code in the
OnRun
trigger of the codeunit:ZipFile.CREATE('C:\Users\Public\Pictures\Sample Pictures\Pictures.zip'); CREATE(MSShell, FALSE, TRUE); ZipFolder := MSShell.NameSpace('C:\Users\Public\Pictures\Sample Pictures\Pictures.zip'); ZipFolder.CopyHere('C:\Users\Public\Pictures\Sample Pictures\Desert.jpg');
Finally, save and close the codeunit.
How it works...
ZipFile
is only a folder with compressed contents, so creating this file or folder is the same as creating a text file using the
CREATE
function. We assigned the namespace of the MSShell
object to...