This project is read-only.

Add file to root of zip file using classic ASP

Aug 9, 2012 at 7:45 PM

I have DotNetZip installed and running fine on a Windows 2008 server.

Using a classic ASP page, I want to bundle a bunch of comma-delimited files to a user and send it over in a zip file.

The following code works fine but it stores all the path information so the files inside the zip file are located in some ridiculous directory like C:\Inetpub\wwwroot\appname\_temp\

I'm using the following code:

Set objZip = CreateObject("Ionic.Zip.ZipFile") 
sFileArray = Split(sFileArray, "|") 
For iCount = 0 To UBound(sFileArray) 
     If sFileArray(iCount) <> "" Then 
          objZip.AddFile sFileArray(iCount) 
     End If 
objZip.Name = sFilePath & "" 
Set objZip = Nothing 

I see that the AddFile method allows you to specify where you want the added file to reside in the zip file if you add a second parameter. According to the documentation objZip.AddFile sFileArray(iCount), "" should put the file in the root of the zip file.

However, when I add that parameter, I get the following error:

Wrong number of arguments or invalid property assignment: 'objZip.AddFile'

Anyone have any idea what I'm doing wrong?


Aug 10, 2012 at 1:50 PM

Try to add "/" for the second parameter instead of just an empty string.

Aug 10, 2012 at 1:55 PM

Yeah, that doesn't work either.

The error indicates that a second parameter isn't even valid for the .AddFile method.

The work-around I found was to call .AddFile_2 buried in the documentation or a bug report (I forget) here.

.AddFile_2 accepts the second parameter and passing it "" puts the files in the root.