Zip from LotusScript in Notes/Domino 6

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 zipClass As JAVACLASS
 Dim zipFileObject As JavaObject
 Dim varFileToZip As String, varOutFilePath 
As String, returnCode As String
 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"
  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
          // Associate a file input stream 
for the current file
          FileInputStream in = 
new FileInputStream(fileToZip);
          // Add ZIP entry to output stream.
(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
          // Close the current file input stream
        // Close the ZipOutPutStream
      catch (IllegalArgumentException iae) {
   return "ERROR_
      catch (FileNotFoundException fnfe) {
      catch (IOException ioe)
      return "ERROR_IOEXCEPTION";

  return "OK";
Credit goes to this article that helped me get zipping to work: Zip meets Java from Devshed.

About the author: Jens Bruntt has been a developer and infrastructure advisor for Notes and Domino projects since 1994 and is an R6 Principal Developer working as project manager or consultant depending on the project's size and requirements. He has a Masters degree in Library- and Information Science. Jens works at Convergens.dk as a senior consultant, primarily architecting Domino browser-based Internet, intranet and extranet sites. He is also a SearchDomino.com site expert.

Do you have comments on this tip? Let us know.

Please let others know how useful it is via the rating scale below. Do you have a useful Notes/Domino tip or code to share? Submit it to our monthly tip contest and you could win a prize and a spot in our Hall of Fame.

This was first published in August 2004

There are Comments. Add yours.

TIP: Want to include a code block in your comment? Use <pre> or <code> tags around the desired text. Ex: <code>insert code</code>

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
Sort by: OldestNewest

Forgot Password?

No problem! Submit your e-mail address below. We'll send you an email containing your password.

Your password has been sent to:

Disclaimer: Our Tips Exchange is a forum for you to share technical advice and expertise with your peers and to learn from other enterprise IT professionals. TechTarget provides the infrastructure to facilitate this sharing of information. However, we cannot guarantee the accuracy or validity of the material submitted. You agree that your use of the Ask The Expert services and your reliance on any questions, answers, information or other materials received through this Web site is at your own risk.