This project is read-only.

ExtractSelectedEntries with parens in filename

Mar 14, 2011 at 11:32 PM

I have the following website code which extracts one file from a zip file, but appears to be having problems if there are parens () in the file name.  Here is a code fragment.

strFileName = "003Monthly Charges 01-2011 (updated).xls"

ObjUnZip.ExtractSelectedEntries("name = '" & strFileName & "'", "", MapPath(Report_Export_Path), ExtractExistingFileAction.OverwriteSilently)

This code works for file names with spaces in the name, but does not extract if there are parens.  Any help would be appreciate as this is my only application that unzips files and I am relatively new to using dotnetzip.



Mar 15, 2011 at 1:19 PM

I'll have to look into this. will get back to you.

Mar 16, 2011 at 12:48 AM

Yes, this is a bug in the file selector logic.   I'll have to apply a fix.

Mar 16, 2011 at 12:57 AM
This discussion has been copied to a work item. Click here to go to the work item and continue the discussion.
Mar 16, 2011 at 3:31 PM

Thanks for investigating this issue.  I found that I also had a second problem which caused an extract to fail.  When I was looking for the filename of 'file1.xls', I found that the value of ZipEntry.FileName was actually 'folderA/file1.xls' and therefore the file was not extracted (probably due to options passed to an old version of the tool used to add to the zip files which used a now obsolete library).  I had to change to the following code to find the file, regardless of how the filename was stored in the zip file.

Dim ObjUnZip As ZipFile

Dim ObjZipEntry as ZipEntry

For Each objZipEntry In ObjUnZip.Entries
                If objZipEntry.IsDirectory Then
                    'do nothing
                    If objZipEntry.FileName.Equals(strFileName) Or objZipEntry.FileName.EndsWith("/" & strFileName) Then
                        objZipEntry.Extract(MapPath(REPORT_EXPORT_PATH), ExtractExistingFileAction.OverwriteSilently)
                        strFoundFileName = objZipEntry.FileName
                    End If
                End If


Do you have any suggestions about setting the parameters of ExtractSelectedEntries so that these filenames would also be found?

Mar 17, 2011 at 11:38 AM

yes - use a wildcard. for example:

  name = */file.xls

should work.

Mar 17, 2011 at 2:26 PM

When I go to extract the file 'file.xls' from a zip file, but I do not know whether the ZIpEntry.FileName is 'file.xls' or 'folder/file.xls', what would I pass to ExtractSelectedEntries so that I would find the file?  Is there the ability to match 'basename' where it matches just the file name and ignores any folders that are in ZipEntry.FileName?

I appreciate your help.  Since I was moving an existing website, I had to stick with the loop above as my customers had trouble for 2 days downloading some files from the zip files before I got it working correctly all of the time.

Mar 20, 2011 at 2:35 PM

I think

name = ./*/basename.xls

...should work.

did you try that?

Mar 21, 2011 at 5:26 PM

Thanks.  I just tried that and it solves my second problem.  How do I find out when the updated library is available that fixes the first problem?