Zip/Compress files in C/SIDE

Waldo
Member Posts: 3,412
I would have to compress all files within a specific folder. Does anyone know how I can do this from within Navision C/SIDE. May be there is some kind of OCX or Automation Server I can use. I thought of using pkzip in a SHELL-command, but isn't there a better solution?
0
Comments
-
Have a look at zlib http://www.gzip.org/zlib/
A DLL of this compression library can be found at http://www.winimage.com/zLibDll/
I did not try this, but maybe you can call this DLL from C/AL code.No support using PM or e-mail - Please use this forum. BC TechDays 2024: 13 & 14 June 2024, Antwerp (Belgium)0 -
Probably this is a stupid question, but I do not seem to succeed in registring the dll with regsvr32. I get the message "zlib.dll was loaded, but the DllRegisterServer entry point was not found."
Can you help me with this?Luc Van Dyck wrote:Have a look at zlib http://www.gzip.org/zlib/
A DLL of this compression library can be found at http://www.winimage.com/zLibDll/
I did not try this, but maybe you can call this DLL from C/AL code.0 -
I searched a while and found this page http://www.dogma.net/markn/FAQ.html#Q27 where you can download zlibocx2.dll. This file can be registered using regsvr32.
Some C/AL code:x.InputFileName := 'd:\words_dutch.txt'; x.OutputFileName := 'd:\words_dutch.zip'; x.Compress; x.InputFileName := 'd:\words_dutch.zip'; x.OutputFileName := 'd:\words_dutch2.txt'; x.Decompress;
where x is a OCX-variabele, pointing to "zlibIF Class".No support using PM or e-mail - Please use this forum. BC TechDays 2024: 13 & 14 June 2024, Antwerp (Belgium)0 -
Thanks for your time!
I was looking too for some OCX-possibilities, and one I found:http://www.freedownloadscenter.com/Programming/Visual_Basic_Components_H-P/Maquisistem_Zip_Compress_OCX.html. Now, this always shows a Pop-up, and it didn't seem to work properly (I always got an error 'bad file name' or something).
Now, I'm trying your possibility, but here, it seems that I only can compress 1 file to 1 zip-file. Now, my main intention was compressing a folder to one file (because, later on, I have to e-mail this file).0 -
A solution COULD be the following:
vZipFile := vDirectory + 'NameZipfile.zip'; vZipCommand := 'pkzip ' + vZipFile + ' ' + vDirectory + '*.html'; SHELL(vZipCommand);
Now, this has as major disadvantage that it is a DOS-routine, which means, that it can't use the long Windows-names. E.g. "Waldos zip file.html" becomes something like "waldos~1.HTM". Also the zip-file itself can't have a long file-name. So, if possible, I would prefer another solution.0 -
What version of pkzip are you using? Version 4.00 DOES support long filenames.No support using PM or e-mail - Please use this forum. BC TechDays 2024: 13 & 14 June 2024, Antwerp (Belgium)0
-
Indeed, I was using 2.50.
I found a better pkzip now at http://burks.brighton.ac.uk/burks/software/compress/install.sw?3.cutezip2.exe. It's not pkzip, but pkzipc and works slightly different. Here is my code:vZipFile := vDirectory + 'ZipFile.zip'; vZipCommand := 'pkzipc -add ' + vZipFile + ' ' + vDirectory + '*.html'; SHELL(vZipCommand);
Thanks for the help!0 -
Hi! I'm using the Zip Compress OCX from Binarywork in version 3.0.98. Works fine.0
-
You can use "Microsoft Shell Controls And Automation" to zip an entire folder. Parse FolderItems for specified files.
//Variable IntegerValue Integer i Integer Shell32 Automation 'Microsoft Shell Controls And Automation'.Shell SrcFolder Automation 'Microsoft Shell Controls And Automation'.Folder DstFolder Automation 'Microsoft Shell Controls And Automation'.Folder SrcItems Automation 'Microsoft Shell Controls And Automation'.FolderItems3 TextFile File ZipFileName Text 1024 SourceFolderName Text 1024 //Code //Zip file Initialization TextFile.CREATE(ZipFileName); TextFile.TEXTMODE(FALSE); IntegerValue:=101010256; TextFile.WRITE(IntegerValue); IntegerValue:=0; FOR i:=1 TO 9 DO TextFile.WRITE(IntegerValue); TextFile.CLOSE; IF CREATE(Shell32) THEN; SrcFolder:=Shell32.NameSpace(SourceFolderName); DstFolder:=Shell32.NameSpace(ZipFileName); SrcItems:=SrcFolder.Items; DstFolder.CopyHere(SrcItems);
You can find 'Microsoft Shell Controls And Automation' in all Microsoft Windows computer from W95. \:D/0 -
Previous way of compressing file is pretty good and simple. But You must take care that compressed folders are supported only in XP/2003 Windows versions. For 98/ME/2000 You need to register additional DLL's which could be taken from MS udpate site (searching here)
After this, copy files from downloaded file: zipfldr.dll,dunzip32.dll and dzip32.dll into Windows\System or Windows\System32 (depends on OS) directory and register zipfldr.dll with regserv:
regserv32 X:\windows\system32\zipfldr.dll
Should work:)
Thanks for the way described.
Maybe somebody tried using CAB?:)0 -
Hi
When testing Albertos code example above I'm getting an error: "An exception occurred from an external component."
What am I doing wrong?
Specifically the error occours when executing the "DstFolder:=Shell32.NameSpace(ZipFileName);" statement - I'm guessing because ZipFileName points to a file and not a folder?// Vars IntegerValue Integer i Integer Shell32 Automation 'Microsoft Shell Controls And Automation'.Shell SrcFolder Automation 'Microsoft Shell Controls And Automation'.Folder DstFolder Automation 'Microsoft Shell Controls And Automation'.Folder SrcItems Automation 'Microsoft Shell Controls And Automation'.FolderItems3 TextFile File ZipFileName Text 1024 SourceFolderName Text 1024 //Code ZipFileName := 'c:\test.zip'; SourceFolderName := 'c:\test'; TextFile.CREATE(ZipFileName); TextFile.TEXTMODE(FALSE); IntegerValue:=101010256; TextFile.WRITE(IntegerValue); IntegerValue:=0; FOR i:=1 TO 9 DO TextFile.WRITE(IntegerValue); TextFile.CLOSE; if isclear(Shell32) then CREATE(Shell32); SrcFolder:=Shell32.NameSpace(SourceFolderName); DstFolder:=Shell32.NameSpace(ZipFileName); SrcItems:=SrcFolder.Items; DstFolder.CopyHere(SrcItems);
Besides this I'd like to know which modifications I have to make in the code in order to be able to compress (and de-compress) single files?
Thanks in advance!0 -
Which version of OS are u using? Is ZIP Folders functionality enabled?
About working with seperate files, it's the same as working with standart folders. F.e. you can define Folder.CopyHere(filename) and so on.0 -
Thanks for your reply.
I'm on WinXP.
I don't know if ZIP folders functionality is enabled or disabled - is this configurable? I was hoping to write code that would be executable on any WinXP machine.
If I understand you correct,//Var Shell32 Automation 'Microsoft Shell Controls And Automation'.Shell SrcFile Automation 'Microsoft Shell Controls And Automation'.Folder //Code SomeFileName := 'c:\test.txt'; SrcFile := Shell32.NameSpace(SomeFileName)
is legal?0 -
AndersNordmann wrote:Thanks for your reply.
I'm on WinXP.
I don't know if ZIP folders functionality is enabled or disabled - is this configurable? I was hoping to write code that would be executable on any WinXP machine.
You can re-enable it by running (if it is turned off):
regsvr32 zipfldr.dllAndersNordmann wrote:If I understand you correct,//Var Shell32 Automation 'Microsoft Shell Controls And Automation'.Shell SrcFile Automation 'Microsoft Shell Controls And Automation'.Folder //Code SomeFileName := 'c:\test.txt'; SrcFile := Shell32.NameSpace(SomeFileName);
is legal?//Var Shell32 Automation 'Microsoft Shell Controls And Automation'.Shell ZIPFolder Automation 'Microsoft Shell Controls And Automation'.Folder ZipFile Text250 SomeFileName Text250 IntVal Integer //Code //>>CREATING ZIP FILE ZipFile.CREATE('c:\myzipfolder.zip'); //here goes Your zip filename ZipFile.TEXTMODE(FALSE); //binary mode IntVal:=101010256; //>>writing zip header ZipFile.WRITE(IntVal); IntVal:=0; FOR i:=1 TO 9 DO ZipFile.WRITE(IntVal); //<<writing zip header ZipFile.CLOSE; //<<zip file created c:\myzipfolder.zip CREATE(Shell32); //creating shell automation ZIPFolder:=Shell32.NameSpace('c:\myzipfolder.zip'); //ZIPFolder is now our folder in zip format which will be used SomeFileName := 'c:\test.txt'; //>>Copying file to our zip folder ZIPFolder.CopyHere(SomeFileName); CLEAR(Shell32); //<<finish:)
Hope it helps0 -
I've tried registering the dll (zipfldr.dll) but the code still errors out.
// Vars IntegerValue Integer i Integer Shell32 Automation 'Microsoft Shell Controls And Automation'.Shell ZipFolder Automation 'Microsoft Shell Controls And Automation'.Folder ZipFileName Text 1024 ZipFile File SourceFileName Text 1024 //Code ZipFile.CREATE('c:\myzipfolder.zip'); //here goes Your zip filename ZipFile.TEXTMODE(FALSE); //binary mode IntegerValue:=101010256; ZipFile.WRITE(IntegerValue); IntegerValue:=0; FOR i:=1 TO 9 DO ZipFile.WRITE(IntegerValue); ZipFile.CLOSE; CREATE(Shell32); ZipFolder:=Shell32.NameSpace('c:\myzipfolder.zip'); SourceFileName := 'c:\myfile.txt'; ZipFolder.CopyHere(SourceFileName); CLEAR(Shell32);
The error occours when executing:ZipFolder:=Shell32.NameSpace('c:\myzipfolder.zip');
If I replace 'c:\myzipfolder.zip' with 'c:\myzipfolder' (and create the folder beforehand) I get no error, but obviously no zipfile either
Maybe the zipfolder-functionality isn't completely enabled since it looks like windows won't recognize the zipfile as a folder??? - or maybe there is another way to make windows recognize the zipfile as a folder??0 -
Seems that You've installed archiver which disabled zipfolders functionality and also associated zip files?
Can You view files in zip folder using explorer? Put one zip file to disk c, open explorer and on left treebar you must see it (folder with zigzag).0 -
Thanks for your help IB.
It seems that registrering zipfldr.dll requires re-boot in order to take effect
It works now, but I think I have to solve this using a different approach- registrering the dll from navision is ok, but booting the machine, I think not...
I think I'll be going with ZlibOCX2.dll which I can export and register when I need it.
Btw. do you know how well the compression within BLOB-fields work?0 -
About ZLibOCX - I prefer MS OS features more, but it's your choice
In my case rebooting pc is not a problemAlso I don't like licensing problems with such OCXes, no support and so on
About BLOB's - actually have no ideaTill now
0 -
Is it possible that you provide a similar function for "UnZipFolder"?
Thanks in advance!alberto.done wrote:You can use "Microsoft Shell Controls And Automation" to zip an entire folder. Parse FolderItems for specified files.//Variable IntegerValue Integer i Integer Shell32 Automation 'Microsoft Shell Controls And Automation'.Shell SrcFolder Automation 'Microsoft Shell Controls And Automation'.Folder DstFolder Automation 'Microsoft Shell Controls And Automation'.Folder SrcItems Automation 'Microsoft Shell Controls And Automation'.FolderItems3 TextFile File ZipFileName Text 1024 SourceFolderName Text 1024 //Code //Zip file Initialization TextFile.CREATE(ZipFileName); TextFile.TEXTMODE(FALSE); IntegerValue:=101010256; TextFile.WRITE(IntegerValue); IntegerValue:=0; FOR i:=1 TO 9 DO TextFile.WRITE(IntegerValue); TextFile.CLOSE; IF CREATE(Shell32) THEN; SrcFolder:=Shell32.NameSpace(SourceFolderName); DstFolder:=Shell32.NameSpace(ZipFileName); SrcItems:=SrcFolder.Items; DstFolder.CopyHere(SrcItems);
You can find 'Microsoft Shell Controls And Automation' in all Microsoft Windows computer from W95. \:D/Timo Lässer
Microsoft Dynamics NAV Developer since 1997
MSDynamics.de - German Microsoft Dynamics Community - member of [clip]0 -
ZIP Folders is great of cause but how does one create a NEW zip file with it ? As far as i can find it only allows to decompress from existing zip or add new files to EXISTING zip0
-
Hi, I need to create a Zip file password protected. anyone knows0
-
Hi Guys,
have anyone a solution to make a GZIP (Not ZIP) File ?
The GZIP dll and the GZIP OCX from Page 1 doesn work in my case.
Any Ideas ?
Thx & Greetz
CBT0 -
Hi All.
I (like many before) have to zip a bunch of files then email them to a customer .
I have read many strings on the subject and the blow code (kind of) works for me// Vars IntegerValue Integer i Integer Shell32 Automation 'Microsoft Shell Controls And Automation'.Shell SrcFolder Automation 'Microsoft Shell Controls And Automation'.Folder DstFolder Automation 'Microsoft Shell Controls And Automation'.Folder SrcItems Automation 'Microsoft Shell Controls And Automation'.FolderItems3 TextFile File ZipFileName Text 1024 SourceFolderName Text 1024 //Code ZipFileName := 'c:\test.zip'; SourceFolderName := 'c:\test'; TextFile.CREATE(ZipFileName); TextFile.TEXTMODE(FALSE); IntegerValue:=101010256; TextFile.WRITE(IntegerValue); IntegerValue:=0; FOR i:=1 TO 9 DO TextFile.WRITE(IntegerValue); TextFile.CLOSE; if isclear(Shell32) then CREATE(Shell32); SrcFolder:=Shell32.NameSpace(SourceFolderName); DstFolder:=Shell32.NameSpace(ZipFileName); SrcItems:=SrcFolder.Items; DstFolder.CopyHere(SrcItems);
but im an inquisitive so and so... therefore i have a few questions and would like to take the process to another level of complexity
first my questions
1.What is the relevance of
IntegerValue:=101010256;
2.Whats the point of the loop?
FOR i:=1 TO 9 DO
Now for the complexity
If (as i suspect) the loop is simply a filler of time to allow for the zip process to work, then how would I develop the code to allow for a variable number of files. For example I am trying to compress our Proof Of Delivery .tif files per customer and Email them to the customer. One customer folder might contain 1800 documents the next may only hold 1. so putting a static loop of 9 may delay the process where it doesnt need to be delayed.
A further complexity issue relates to the email section of the process. Due to email poliocy, the biggest email attachment i can send is 3 Meg. So how would i split this zipping process to create a new zip file each time the file exceeds the 3MB size limit??
As always, thanks in advance
M@M@
I have seen the future and it's egg shaped.0 -
Anyone knows something about Password?0
-
jhenav wrote:Anyone knows something about Password?
this is an old story.. hope u fixed it.. if not hope this will help u
http://www.mibuso.com/dlinfo.asp?FileID=1445Thinking, programming, coding, developing == Music!0 -
euekim wrote:jhenav wrote:Anyone knows something about Password?
this is an old story.. hope u fixed it.. if not hope this will help u
http://www.mibuso.com/dlinfo.asp?FileID=1445
Hi,
URL given above is dependent on 3rd party tool. Instead of that with the existing 'Microsoft Shell Controls And Automation' is it possible to use Password?
Thanks in advance.
Regards,
Sanjeev0 -
yes u can used it to zip a file with password.
hope it helpsThinking, programming, coding, developing == Music!0
Categories
- All Categories
- 73 General
- 73 Announcements
- 66.6K Microsoft Dynamics NAV
- 18.7K NAV Three Tier
- 38.4K NAV/Navision Classic Client
- 3.6K Navision Attain
- 2.4K Navision Financials
- 116 Navision DOS
- 851 Navision e-Commerce
- 1K NAV Tips & Tricks
- 772 NAV Dutch speaking only
- 617 NAV Courses, Exams & Certification
- 2K Microsoft Dynamics-Other
- 1.5K Dynamics AX
- 320 Dynamics CRM
- 111 Dynamics GP
- 10 Dynamics SL
- 1.5K Other
- 990 SQL General
- 383 SQL Performance
- 34 SQL Tips & Tricks
- 35 Design Patterns (General & Best Practices)
- 1 Architectural Patterns
- 10 Design Patterns
- 5 Implementation Patterns
- 53 3rd Party Products, Services & Events
- 1.6K General
- 1.1K General Chat
- 1.6K Website
- 83 Testing
- 1.2K Download section
- 23 How Tos section
- 252 Feedback
- 12 NAV TechDays 2013 Sessions
- 13 NAV TechDays 2012 Sessions