The ServerZip component is inserted into the page, and the properties and methods used, in the same way as the standard components supplied with Active Server pages.
In VBScript:
<%
Set objSZ = Server.CreateObject("Stonebroom.ServerZip2")
objSZ.sourceFileList = "/MyDirectory/MyFile.doc"
objSZ.zipFileName = "MyNewFile.zip"
objSZ.virtualTargetRoot = "/Downloads"
blnWorked = objSZ.doZip()
%>
Alternatively, in JScript:
<%
objSZ = Server.CreateObject('Stonebroom.ServerZip2');
objSZ.sourceFileList = '/MyDirectory/MyFile.doc';
objSZ.zipFileName = 'MyNewFile.zip';
objSZ.virtualTargetRoot = '/Downloads';
blnWorked = objSZ.doZip();
%>
This provides some introduction text in the page (depending on the version),
and when complete a hyperlink that the user can download the file by clicking on.ServerZip works best if buffering is enabled in the ASP page. It can then flush sections of the page to the browser as the code executes. You can turn on buffering by inserting the line:
<% Response.Buffer = True %>before the opening <HTML> tag in your page. You may also need to increase the timeout for the ASP script if you are likely to be compressing large files, by also inserting a line such as:
<% Script.Timeout = 120 %>here as well. This example sets the timeout for the page to 2 minutes. The component can only process one zip operation at a time (although concurrent file listing and delete operations are allowed). This helps to prevent overloading of the server by the processor-intensive compression code. You can query the components zipIsBusy property to see if it is in use:
'see if the component is busy or can start the zip operation If objSZ.zipIsBusy Then Response.Write "Waiting to access the component ...<P>" Response.Flush 'force display by the browser with two Write and Flush operations Response.Write "" Response.Flush 'then wait for up to one minute for the component to become available intWaitUntil = (Minute(Now) + 1) Mod 60 Do While (objSZ.zipIsBusy) And (Minute(Now) <> intWaitUntil) Loop End If If objSZ.zipIsBusy Then 'still busy after 1 minute Response.Write "Sorry, the component is too busy at present.<P>" Response.Flush Else 'OK to do the zip blnWorked = objSZ.doZip() 'call the doZip method to create the new zip file End IfNote: If you are using Internet Information Server version 4, you will get more reliable results if you set the 'Run in separate memory space (isolated process)' option on the Virtual Directory page of the Properties dialog for any directories where you have pages that use the ServerZip component.
You can also control some of the features and provide a more secure environment for your server using the Security Manager application, named SZConfig.exe, which is installed in the Stonebroom directory.
To compress files, you must set the appropriate properties then call the doZip() method. An error occurs if a required
property is not set correctly.
Property
Description
sourceFileList
String. Can be either a full physical file path and name or a
virtual directory path and name. For a physical path, the '*' wildcard character can be used, for example: c:\uploads\* to include all files. Provided that you have version 2.509 or higher of the compression DLL lspzipx.dll installed (see the support pages for details of how to upgrade), you can also use UNC path names - i.e. paths that start with \\servername.
To specify more than one individual file, separate the individual file names with vertical bar ('|' or pipe) characters.
Filenames that include spaces can be enclosed in double quotes when using a physical path, for example:
c:\documents\mydoc.doc|"c:\My Documents\another.doc"|c:\uploads\*
If a virtual path is used, only one file can be specified and it cannot include wildcards. ServerZip will use
the Alias mappings and structure of your Web site to find the file. File names that include spaces do not require
enclosing in double quotes when a virtual path is specified. From version 2.4x onwards, UNC path names can also be used - for example \\myserver\c\documents\mydoc.doc (see 'Getting the latest version of ServerZip' in the support pages to upgrade from an earlier version).
You can prevent physical paths from being used with the Security Manager utility installed in
your Stonebroom directory. Note: if you are using JavaScript to specify a physical directory you must use
double slashes in the file specification, for example c:\\documents\\mydoc.doc.
zipFileName
String. The file name only for the target zip file.
This will be placed within a uniquely named directory ready for the user to collect.
virtualTargetRoot
String. The base virtual directory within which the unique
download directory will be created. This allows multiple concurrent zip operations with the same zip file name
to occur. Must be a virtual, not a physical, directory specification.
compressionRate
Optional Integer. Specifies the compression rate for the file, with values from 0 to 9. 0 is
fast speed with no compression, while 9 is slow speed but gives the highest compression rate. The default if not specified is 5.
recurseDirs
Optional Boolean. If True, specifies that files in the subdirectories below the source file
directory, and which match the source file specification, will be included in the zip file. The default is False.
To include all files use a single asterisk character for the filename, for example: c:\uploads\*.
This option can be completely disabled to all users with the Security Manager utility installed in your Stonebroom directory.
deleteOriginalFiles
Optional Boolean. If True, specifies that all the original files that are included in the zip file
will be deleted once the compression has competed successfully. The default is False.
This option can be completely disabled to all users with the Security Manager utility installed in your Stonebroom directory.
encryptString
Optional String. A code string of up to 65 characters that is used to securely encrypt the contents of the zip file.
To avoid language and character set conflicts, it is wise to use only standard ASCII characters. The encrypt code is case-sensitive, and cannot contain spaces.
An empty string means that the file is not encrypted. This is the default.
hideResponse
Optional Boolean. If True the component will not create any output to the browser, and will not show the introduction message or the link to download the zip file. The default is False. You can obtain the virtual path of the zip file once the operation is complete by querying the zipfileDownloadHref property, and error details from the optional parameters added to the doZip method in version 2.2. NOTE: this feature is not implemented in Evaluation copies of ServerZip.
useUniqueFolder
Optional Boolean. Added in version 2.3x. If True the component will create a directory with a unique name within the folder specified by the virtualTargetRoot property, and place the zipped download file there to prevent any chance of other users overwriting it with a file of the same name. This is the default behavior. By setting this parameter to False, however, the file will be placed directly in the folder specified by the virtualTargetRoot property. In this case you must ensure that each file has a unique name. NOTE: this feature is not implemented in Evaluation copies of ServerZip.
zipIsBusy
Read-Only Boolean. Returns True if the component is currently busy and unable to handle another zip operation, or False if OK.
The account that the component is running under must have Read/Write/Delete permission for the Temporary directory on your system for this property to work correctly. The
Temporary directory is usually specified by the TMP or TEMP environment variable, and the default is usually C:\Temp or Winnt\Temp. In versions 2.2 and above the path can be obtained from the getTempFilePath method.
zipfileDownloadHref
Read-Only String. Returns the full virtual path and filename of the zip file as a string, once compression is complete.
Methods
Parameters
Description
doZip
Starts the compression process, using the property values previously set, or the defaults where not specified.
Returns True if the process completes successfully, or False otherwise.
ErrorNumber
Optional. Integer. On return from the function this parameter (if supplied) contains the internal error code number, or zero if there was no error. See Error Numbers for a full list. Added in version 2.2
ErrorText
Optional. String. On return from the function this parameter (if supplied) contains a text message containing the error details or a 'success' message. See Error Numbers for a full list. Added in version 2.2
getTempFilePath
(none)
Returns a String containing the full path to the folder where temporary files will be created while the zip process is executing. Added in version 2.2
To list the names of files that are stored on the server in the users's browser, you must provide the directory name. You can also specify text and HTML that is placed before and/or after each file in the list.
To create the listing, you then call the fileListing() method, with an optional parameter that is a file specification which limits the files included in the list to those that match the specification.
Property
Description
fileListRoot
String. Can be either the full physical
path or the virtual path of the directory where the files that are to be listed reside.
You can prevent physical paths from being used with the Security Manager utility installed in your Stonebroom directory.
beforeFileHTML
Optional String. The text and HTML that is placed before each file in the listing.
Allows you, for example, to create <OPTION> lists, <A> hyperlinks, or format file names as required. The default if omitted
is an empty string.
afterFileHTML
Optional String. The text and HTML that is placed after each file in the listing.
Allows you to add closing element tags, or format file names as required. The default if omitted
is a carriage return.
Method
Parameter
Description
fileListing
Starts the file listing, using the property values previously set, or the defaults where not specified. Returns a count of the number of files listed.
FileSpecification
Optional. String containing the specification, including wildcards if required, of the files to include - i.e. sz*.doc. The default if omitted is *.* (all files).
Each doZip() process creates a new unique directory within an existing virtual directory on the server, and places the zip file that is to be downloaded within it.
To remove the old directories, you use the deleteOldFiles() method. You can specify how many days old the directory must be before it is deleted.
Property
Description
virtualTargetRoot
String. The base virtual directory from which the unique
download directories will be deleted. Must be a virtual, not a physical, directory specification.
daysOldToDelete
Optional Integer. Specifies the number of days that the download directories must be older than in order to be deleted. The default if omitted is 2.
Method
Parameters
Description
deleteOldFiles
None
Starts the delete process using the property values previously set, or the defaults where not specified.
Returns a count of the number of directories successfully deleted.
The ServerZip component provides wide-ranging access to all the drives and directories of your server, and could possibly be used by unwelcome visitors to cause damage to the server installation. To prevent this, you can set options that control how much freedom the component has to access files and directories. These setting are stored in Windows Registry under the key:
HKEY_LOCAL_MACHINE\SOFTWARE\Stonebroom\ServerZip\The settings are:
| Key | Description |
| AllowVirtualSourceOnly | A value of "1" prevents the sourceFileList property from being set to a physical path. Only virtual directories can be specified as the source of files to compress. The default value of "0" allows either physical or virtual directories to be specified. |
| AllowVirtualFileListOnly | A value of "1" prevents the fileListRoot property from being set to a physical path. Only virtual directories can be specified as the source of files to list. The default value of "0" allows either physical or virtual directories to be specified. |
| DisableDeleteOriginalFiles | A value of "1" prevents the deleteOriginalFiles property from being set to True, and so the original files cannot be deleted. The default value of "0" allows the original files to be deleted. |
| DisableIncludeSubdirectoryFiles | A value of "1" prevents the recurseDirs property from being set to True, and so files in subdirectories cannot be included in the compressed file. The default value of "0" allows the subdirectory contents to be included. |
The easiest way to change the settings is to run the Security Manager utility, named SZConfig.exe, which is installed in the Stonebroom directory. This provides a checkbox for each Registry setting, allowing you to change it easily.