Zipping folders and files within NAV
This might not be a common task, but creating files and e-mailing them from within NAV is. You can combine this with those recipes to send large groups of files at once.
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
Add the following code to the
OnRun
trigger: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');
Save and close the codeunit.
How it works...
A ZIP file is really just a folder that happens to have its contents compressed. We can create this file or folder just as we would create a text file, using the CREATE...