Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Create ZIP file with help of LotusScript or JavaScript

733 views
Skip to first unread message

Vladimir Palko

unread,
Sep 29, 2004, 11:25:09 AM9/29/04
to
Hello everybody,

How can I ZIP any various files on my HDD with help of LorusScript or
JavaScript and attach it to an e-mail?
It has not to use any outside ZIP compressor.
Also this ZIP file should be created with a password.

Is it possible?

Thanks
-VP


Karl-Henry Martinsson

unread,
Sep 29, 2004, 2:34:41 PM9/29/04
to
"Vladimir Palko" <pa...@cms.vinnica.ua> wrote in message
news:10964717...@pecker.nest.vinnica.ua...

I assume it is possible if you know the ZIP format and algorithm, and is
willing to rewrite a ZIP-program in LotusScript (or possibly Java).
Explain why you can't call an external EXE or DLL.

Otherwise I don't see why you can't take an external DLL or COM-object
and call it to generate the ZIP-file, then attach it to your document.
I am using the commandline interface to WinZIP myself, but I have also
been using a free, commandline ZIP tool earlier. Then you just call the
program to generate the ZIP file, wait for it to be created and then
attach it or upload it to an ftp server (and update the document with
information about the location of the ZIP file).

/KHM


Vladimir Palko

unread,
Sep 29, 2004, 2:47:16 PM9/29/04
to
I don't know if user has external ZIP program on his PC so I would not call
any external EXE or DLL.
I would like to have LotusScript or JavaScript for doing it.
But it is obligatory to have posibility to password protect the compressed
file.
Could you provide me with any example you wrote in your letter?
Thanks


"Karl-Henry Martinsson" <k...@suespammers.org> wrote in message
news:2s0djbF...@uni-berlin.de...

Karl-Henry Martinsson

unread,
Sep 29, 2004, 3:29:42 PM9/29/04
to
(top posting fixed)

1) The user(s) probably won't have any external EXE or DLL files, but
how hard is it to distribute them? I have been writing code that check
for teh existence of a certain file, and if it is not there, detach it
from the database and put it in teh right place. Not very complicated at
all.

2) The code to call an external file is really simple. This is how I did
it when I wanted a file to be uploaded to an ftp server. You would do
the same to create the ZIP file. Not complete code, but you get the
idea...

batchfile = "c:\windows\temp\ftp.txt"
Open batchfile For Output As #1
Print #1, FTPuser
Print #1, FTPpass
Print #1, "cd " & FTPhomedir
Print #1, "mkdir " & parentunid
Print #1, "cd " & parentunid
Print #1, "mkdir " & thisdocunid
Print #1, "cd " & thisdocunid
Print #1, "binary"
Print #1, |send "| & filename & |" "| & filename & |"|
Print #1, "bye"
Close #1

Open "c:\windows\temp\upload.bat" For Output As #2
Print #2, "c:"
Print #2, "cd\"
Print #2, "ftp -v -s:c:\windows\temp\ftp.txt " & FTPserver
Close #2
commandline = "c:\windows\temp\upload.bat"
Call ShellAndWait(commandline)

Kill "c:\windows\temp\ftp.txt"
Kill "c:\windows\temp\upload.bat"


Note: ShellAndWait is a function that call the Win32 API to shell out to
the operating system and execute a comamnd, waiting for teh command to
finish before returning control to the Notes client. YOu can use the
regular Shell() in LotusScript, but that command does not wait. You can
find ShellAndWait online.

If you need help writing the code to automatically detach the required
file to the user's hard disk, or to write the actual function to create
the ZIP file, feel free to mail me. My standard consultant fee applies.

/KHM


Vladimir Palko

unread,
Sep 30, 2004, 3:43:23 AM9/30/04
to
Detaching and run PKZIP.EXE with help of Shell command seems to be slow.
So I prefer to pack the file by some Lotus or Java script.
I found an example here:
http://searchdomino.techtarget.com/tip/1,289483,sid4_gci1002690,00.html

But it doesn't use the password
Thoughts?
:(

>
> 1) The user(s) probably won't have any external EXE or DLL files, but
> how hard is it to distribute them? I have been writing code that check
> for teh existence of a certain file, and if it is not there, detach it
> from the database and put it in teh right place. Not very complicated at
> all.
>
> 2) The code to call an external file is really simple. This is how I did
> it when I wanted a file to be uploaded to an ftp server. You would do
> the same to create the ZIP file. Not complete code, but you get the
> idea...
>

>
>

Vladimir Palko

unread,
Sep 30, 2004, 7:25:49 AM9/30/04
to
Ok.. Is it possible to store PKZIP.EXE file in the DB as Shared
Resource->Files?
How can then I get it and use from resource location.
I think it would be better than use it from alone document in the DB
-Thanks

Vladimir Palko

unread,
Sep 30, 2004, 7:25:49 AM9/30/04
to
Ok.. Is it possible to store PKZIP.EXE file in the DB as Shared
Resource->Files?
How can then I get it and use from resource location.
I think it would be better than use it from alone document in the DB
-Thanks

> 1) The user(s) probably won't have any external EXE or DLL files, but

Karl-Henry Martinsson

unread,
Sep 30, 2004, 7:08:25 PM9/30/04
to
"Vladimir Palko" <pa...@cms.vinnica.ua> wrote in message
news:10965302...@pecker.nest.vinnica.ua...

> Detaching and run PKZIP.EXE with help of Shell command seems to be
slow.
> So I prefer to pack the file by some Lotus or Java script.
> I found an example here:
>
http://searchdomino.techtarget.com/tip/1,289483,sid4_gci1002690,00.html
>
> But it doesn't use the password
> Thoughts?
> :(

1) Please don't top post.

2) Write a Java library for zipping that support passwords.

3) Don't use PKZIP, use a faster program. :-) I am sure there are other
programs out there. How many files are you talking about to process? For
one or two files, it should not be much overhead to shell out to the OS,
compared with the actual compression time. And the time the actually
compression takes will be the same no matter if you use an external
program/dll or a Java script library.
Example: You want to compress a 2 MB file. The time to compress is say 6
seconds. To shell out to the operating system and initiate the
compression using an external program might take what, 0.5 seconds?
Probably less, I run similar things (with very short processing time)
where you can't even see the windows, you just see something flicker and
it is gone.
If you wrote that in Lotusscript using a Java library, perhaps it only
take 0.1 second to load the code, etc. So 6.1 second vs. 6.5... Not a
big difference.
Hav eyou been doing some testing? How big are you files you want to
compress? How long is the actual compression time?

Oh, and of course I am not talking about detaching pkzip.exe every time
you run the code, you do it once, the first time the user open the
database...

/KHM


Karl-Henry Martinsson

unread,
Sep 30, 2004, 7:11:02 PM9/30/04
to
"Vladimir Palko" <pa...@cms.vinnica.ua> wrote in message
news:10965435...@pecker.nest.vinnica.ua...

> Ok.. Is it possible to store PKZIP.EXE file in the DB as Shared
> Resource->Files?

I doubt that. You need to detach it to the local drive the first time
teh user open your database.

/KHM

PS. http://www.caliburn.nl/topposting.html

--
A. Because it breaks the logical order of conversation.
Q. Why is top posting bad?


mb¤

unread,
Oct 1, 2004, 5:33:21 AM10/1/04
to
In post: 10965435...@pecker.nest.vinnica.ua,
Vladimir Palko <pa...@cms.vinnica.ua> made a huge mistake by typing:

Attach it on the form in design and then when that db is opened you test
whether the file is there (if it's not just detach it).


The other solution is to call Java agent that creates the zip file.

Look at this (I've found this in my knowledge db, I don't remember where had
I found it):

LotusScript does not have a native class for compressing files to .zip
format. In this tip, I'll show you how change that, if you are running Notes
or Domino R6 (or newer), by using the ability of LotusScript to make calls
to functionality that is available in the Java language. This is done using
LS2J -- which is documented in Designer Help.

I have an agent that holds the following code in Initialize:

Sub Initialize

Dim js As JAVASESSION

Dim zipClass As JAVACLASS

Dim zipFileObject As JavaObject

Dim varFileToZip As String, varOutFilePath As String, returnCode As String


Set js = New JAVASESSION

Set zipClass = js.GetClass("ZipFile")

Set zipFileObject = zipClass.CreateObject

varFileToZip = "c:tempdocument.doc"

varOutFilePath = "c:tempthezipfile.zip"


returnCode = zipFileObject.zipMyFile(varFileToZip, varOutFilePath) 'Calling
the zip function


If Not returnCode = "OK" Then

Print "An Error occurred"

Else

Print "Zip went OK"

End If

End Sub

In the Options of the agent I have the following:

Uselsx "*javacon" 'Which lets you use Java from LotusScript

Use "ZipFile" 'A Java library that holds a function to do zipping

Below is the Java Library that makes it possible to zip a file. You create a
Java Library in the Designer in Shared code -> Script Libraries, click New
Java Library, remove the few lines of code that you get as a help for
getting started, and paste the code below. Save and call the library
"ZipFile."

import java.io.FileInputStream;

import java.io.FileNotFoundException;

import java.io.FileOutputStream;

import java.io.IOException;

import java.util.zip.Deflater;

import java.util.zip.ZipEntry;

import java.util.zip.ZipOutputStream;

public class ZipFile {

public String zipMyFile(String fileToZip, String zipFilePath) {

String result = "";

byte[] buffer = new byte[18024];


// Specify zip file name

String zipFileName = zipFilePath;


try {


ZipOutputStream out =

new ZipOutputStream(new FileOutputStream(zipFileName));


// Set the compression ratio

out.setLevel(Deflater.BEST_COMPRESSION);


System.out.println(fileToZip);

// Associate a file input stream for the current file

FileInputStream in = new FileInputStream(fileToZip);


// Add ZIP entry to output stream.

out.putNextEntry(new ZipEntry(fileToZip));


// Transfer bytes from the current file to the ZIP file

//out.write(buffer, 0, in.read(buffer));


int len;

while ((len = in.read(buffer)) > 0)

{

out.write(buffer, 0, len);

}


// Close the current entry

out.closeEntry();


// Close the current file input stream

in.close();


// Close the ZipOutPutStream

out.close();

}

catch (IllegalArgumentException iae) {

iae.printStackTrace();

return "ERROR_ILLEGALARGUMENTSEXCEPTION";

}

catch (FileNotFoundException fnfe) {

fnfe.printStackTrace();

return "ERROR_FILENOTFOUND";

}

catch (IOException ioe)

{

ioe.printStackTrace();

return "ERROR_IOEXCEPTION";

}

return "OK";


}

}

--
/}
@###{ ]::::::mmmmmmmmm:::::::>
\}


Vladimir Palko

unread,
Oct 1, 2004, 9:12:01 AM10/1/04
to
Hello Karl-Henry,

I am sorry but I don't understand, how can I get an access to the File
Resource by Lorus Script?
I need to create file resource for e.g. PKZIP.EXE file
Then how can it be used?

Thanks

"Karl-Henry Martinsson" <k...@suespammers.org> wrote in message

news:2s3i55F...@uni-berlin.de...

Vladimir Palko

unread,
Oct 1, 2004, 9:15:17 AM10/1/04
to
I think it will be not very big files to compress.
Unfortunately I cannot write a Java library by myself for zipping that
support passwords since I am not familiar with Java just with LotusScript.
Thus I requested for such library here.
Also do you know a faster program than PKZIP?

Thanks

"Karl-Henry Martinsson" <k...@suespammers.org> wrote in message

news:2s3i54F...@uni-berlin.de...

Vladimir Palko

unread,
Oct 1, 2004, 9:22:24 AM10/1/04
to
Hello mbr,

It is a great sample. Thank you very much. Unfortunatrly it doesn't support
passwords. :(


"mb¤" <NoM...@ForSpam.Reasons> wrote in message
news:cjj89b$v45$1...@sunce.iskon.hr...

Karl-Henry Martinsson

unread,
Oct 4, 2004, 3:07:51 PM10/4/04
to
"Vladimir Palko" <pa...@cms.vinnica.ua> wrote in message
news:10966363...@pecker.nest.vinnica.ua...

> > > Ok.. Is it possible to store PKZIP.EXE file in the DB as Shared
> > > Resource->Files?
> >
> > I doubt that. You need to detach it to the local drive the first
time
> > teh user open your database.
> >

> I am sorry but I don't understand, how can I get an access to the File
> Resource by Lorus Script?
> I need to create file resource for e.g. PKZIP.EXE file
> Then how can it be used?
>

Vladimir,

What is it that is so hard to understand?

1) Forget file resources. It will not work. No reason to use it.
2) Stop top-posting. That is considered rude.
3) Write some code like this, to execute when the database is opened:
* Check if PKZIP.EXE exist in a specific location on the local disk.
* If it does not exist, detach it from a specific document that you
have created, with the file attached to a rich text field.
4) Write some code to shell out to the operatin system and run PKZIP.EXE
from there. You have full control of the command line and parameters
as I did show you in an earlier sample.

This is all trivial programming. Nothing complicated at all, everything
is documented in the help file.

/Karl

PS. I will attach the code I am using to detach a file needed by my
system below. Perhaps that will help you. There are of course globals
and constants used there that are not defined in this code, but you get
the idea. I can write you the full code (the detach and the zipping
part), contact me at gmail dot com where my name is "karlhenry".

--
A. Because it breaks the logical order of conversation.
Q. Why is top posting bad?

---------------------------------------------------------
Dim session As New NotesSession
Dim db As NotesDatabase
Dim col As NotesDocumentCollection
Dim doc As NotesDocument
Dim rtitem As NotesRichTextItem
Dim object As NotesEmbeddedObject
Dim query As String
Dim fname As String
Dim filesize As Long
Dim filedate As String
Dim fpath As String
Dim temp1 As String
Dim temp2 As String
Dim notesdir As String
Dim notesdatadir As String

Set db = session.CurrentDatabase
query = |[Form] = "SystemContentDocument" AND [AttachName]="| &
Lcase(COMobject) & |"|
Set col = db.FTSearch(query,0)
Set doc = col.GetFirstDocument
If doc Is Nothing Then
Msgbox "No matching documents found." & Chr$(13) & query
Exit Sub
End If
notesdir = GetNotesDir
notesdatadir = GetNotesDataDir
temp1 = doc.AttachPath(0)
temp2 = strReplace(Lcase(temp1),"%notes%",notesdir)
fpath = strReplace(Lcase(temp2),"%notesdata%",notesdatadir)
Set rtitem = doc.GetFirstItem("Content")
If rtitem.Type = RICHTEXT Then
Forall o In rtitem.EmbeddedObjects
If o.Type = EMBED_ATTACHMENT Then
fname = fpath & "\" & o.Name
If Dir$(fname) = "" Then
somethingwrong:
Msgbox "The file " & fname & " does not exist." & Chr$(13) & "It
need to be installed." & Chr$(13) & "Please contact Deep South
IT.",MB_OK+MB_ICONSTOP,"Missing component"
' Call o.ExtractFile(fname)
' Msgbox o.name & " has been detached into " & fpath & "." &
Chr$(13) & "It may need to be registred with the system." & Chr$(13) &
"Please contact Deep South IT."
Exit Sub
End If
filesize = Filelen(fname)
filedate = Filedatetime(fname)

' If filesize = o.FileSize Then
' Msgbox "Same size"
' Else
' Msgbox "Not same size"
' Call o.ExtractFile(fname)
' End If
If doc.Attachdate(0) = filedate Then
' Msgbox "Same date"
Else
' Msgbox "Not same date"
Print "New version of " & fname & " is being downloaded..."
Call o.ExtractFile(fname)
End If

Exit Forall
End If
End Forall
End If

Vladimir Palko

unread,
Oct 5, 2004, 8:35:20 AM10/5/04
to
Thank you Karl-Henry, and sorry for trouble you for a long time.
I just wanted to know if there are some better ways to store PKZIP.EXE into
the DB.
I expected there is simple way just to use LotusScript or JavaScript in
order to ZIP the file with passwords.
But now I see your suggestion is the best one.
I will make note of of your sample.

Thanks again
-VP

> Vladimir,
>
> What is it that is so hard to understand?
>
> 1) Forget file resources. It will not work. No reason to use it.
> 2) Stop top-posting. That is considered rude.
> 3) Write some code like this, to execute when the database is opened:
> * Check if PKZIP.EXE exist in a specific location on the local disk.
> * If it does not exist, detach it from a specific document that you
> have created, with the file attached to a rich text field.
> 4) Write some code to shell out to the operatin system and run PKZIP.EXE
> from there. You have full control of the command line and parameters
> as I did show you in an earlier sample.
>
> This is all trivial programming. Nothing complicated at all, everything
> is documented in the help file.
>
> /Karl
>
> PS. I will attach the code I am using to detach a file needed by my
> system below. Perhaps that will help you. There are of course globals
> and constants used there that are not defined in this code, but you get
> the idea. I can write you the full code (the detach and the zipping
> part), contact me at gmail dot com where my name is "karlhenry".
>

> ---------------------------------------------------------
> Dim session As New NotesSession
> Dim db As NotesDatabase
> Dim col As NotesDocumentCollection

mb¤

unread,
Oct 5, 2004, 9:09:27 AM10/5/04
to
In post: 10969799...@pecker.nest.vinnica.ua,

Vladimir Palko <pa...@cms.vinnica.ua> made a huge mistake by typing:

Again you're top-posting :)

Compare my post and yours and you'll see what's top-posting.

--
/}
@###{ ]::::::mmmmmmmmm:::::::>
\}


mb¤

unread,
Oct 5, 2004, 9:12:01 AM10/5/04
to
In post: 10969799...@pecker.nest.vinnica.ua,
Vladimir Palko <pa...@cms.vinnica.ua> made a huge mistake by typing:

Since you're using OE, Google for "OE-Quotefix".
Great tool for posting with OE.

--
/}
@###{ ]::::::mmmmmmmmm:::::::>
\}


0 new messages