Home     Products      Support      Corporate     Sign In 
Support Knowledge Base, Article 977
Product
Archive
Version
all
Title
Archive times out when unpacking a zip using more than one Extract() call
Problem

Extract() can accept a filename parameter (which may contain wildcards) to extract only certain files from an archive. This is useful if the programmer only wants to extract certain files.

Some developers wish to call Extract() multiple times. For example, the archive may contain more than just the files that are needed, or some files should be saved in a different location than others from the archive. Unfortunately, the current version of Archive has a known issue when unpacking a zip file using more than one Extract() call. In some cases, Archive may only unzip some of the files and then time out.

This behavior has been determined to occur when calling Extract() more than once and when there are approximately 500 or more files in an archive.

For example, if test.zip contains 700 files the following C# code will timeout:

SAARCHIVELib.ArchiveClass arch = new SAARCHIVELib.ArchiveClass();
arch.ArchiveType = SAArchiveType.SAZip;
arch.PreservePath = true;
arch.OpenArchive(Server.MapPath(".") + "\\test.zip");
arch.ExtractPath = Server.MapPath(".")+ "\\unzipped\\";
arch.Extract("*.txt");
arch.Extract("*.xml");
arch.CloseArchive();
Response.Write("File unzipped.");
Solution

There is a known issue with Archive when unpacking a zip by calling Extract() multiple times, extracting different files each time. In many cases, Archive will unzip some of the files, but will timeout before unzipping all of them.

A workaround to this problem is to extract all the files in the archive and then delete the files you don't want.

  1. Only call Extract() once, as in this C# example:

    SAARCHIVELib.ArchiveClass arch = new SAARCHIVELib.ArchiveClass();
    arch.ArchiveType = SAArchiveType.SAZip;
    arch.PreservePath = true;
    arch.OpenArchive(Server.MapPath(".") + "\\test.zip");
    arch.ExtractPath = Server.MapPath(".")+ "\\unzipped\\";
    arch.Extract("*.*");
    arch.CloseArchive();
    Response.Write("File unzipped.");
    


    Note: In ASP or VB.NET, you can simply call Extract with no parameters, like this:

    arch.Extract()

    In C#, you must pass an empty string or *.*:

    arch.Extract("");
    arch.Extract("*.*");


  2. Then, if there are files that have been extracted that you did not want, you can delete or move them:

    • In .NET, use the native I/O classes for the language you are using to delete files or move them to different directories.
    • In ASP, you can use our FileManager object, which comes bundled with FileUp, to loop through the directory and delete or move files.

      Set FileMgr = Server.CreateObject("SoftArtisans.FileManager")
      Set folder = FileMgr.GetFolder(arch.ExtractPath)
      dim ext 
      
      For Each file In folder.Files
          ext = Mid(file.ShortName, InstrRev(file.ShortName, ".") + 1)
          if ext <> "jpg" then
             FileMgr.DeleteFile file.Path
          end if
      Next
      
Created : 4/5/2005 2:00:03 PM (last modified : 4/5/2005 2:00:02 PM)
Rate this article!
 
Comments