Home     Products      Support      Corporate     Sign In 
Support Knowledge Base, Article 798
Product
XFile
Version
all versions
Title
How do I download a zip file and extract it on the client?
Problem
XFile distributes with Soft Artisans' Archive, which can be used client-side to create and extract "*.zip" and "*.cab" files. This article demonstrates how to use XFile to download a zip file, then instantiate Archive to extract the zipped files automatically.
Solution
Understanding the Code:

As Active X controls, XFile and Archive are each instantiated in HTML via the <OBJECT> tag.

  • To instantiate Archive, set the "clsid" attribute of the <OBJECT> tag to "clsid:D3400FEE-041F-11D3-B1C5-00A0C9B4587A"
  • To instantiate the file transfer engine of XFile, the XFRequest object, set the "clsid" attribute of the <OBJECT> tag to "clsid:C3A57B60-C117-11D2-BD9B-00105A0A7E89"
  • To automate the actions of XFile and Archive, simply refer to each object by the name provided in the "ID" attribute of each <OBJECT> tag.

In the script below, XFile makes an HTTP "GET" request, receives the file in the HTTP Response and saves the file to the client. As part of this, XFile triggers its own OnTransferComplete event which serves as an appropriate place from which to launch the Archive related functions. Here you can open the downloaded archive and extract the files to the client's file system.

<HTML>
<BODY>

<CENTER><H2>IE Based SA-XFile "Get" Sample</H2>
<FORM action="saxfile_get.asp" method="post" id="form1" name="form1">
This page makes a "GET" Request with the XFRequest Object.<br>
It will download a zip file, and then use Archive to extract <br>
the contents to a folder on the client.
<p>
<INPUT Type="button" Name="GetButton" value="Get!">
</p>
</form>
</CENTER>

<!-- Instantiate XFile's XFRequest Object -->
<OBJECT classid="clsid:C3A57B60-C117-11D2-BD9B-00105A0A7E89"
      codebase="/SAXFileSamples/saxfile.cab" id="objXFRequest" VIEWASTEXT>
</OBJECT>

<!-- Instantiate Archive -->
<OBJECT classid="clsid:D3400FEE-041F-11D3-B1C5-00A0C9B4587A"
      Codebase="/SAXFileSamples/saxfile.cab" ID="objArchive" VIEWASTEXT>
</OBJECT>
<SCRIPT>
Dim pathToFileOnServer
  '-- Path of the zip file to be downloaded from the webserver
  pathToFileOnServer = "http://localhost/GetZipFileFromHere/test.zip"

Dim pathToFileOnClient
  '-- Path to where the zip file should be saved on the client
  pathToFileOnClient = "C:\Downloads\myDownloadedZipFile.zip"

Dim pathExtract
  '-- Path on the client to which the zipped files should be extracted
  pathExtract = "C:\Downloads\ExtractedFiles\"

  Sub GetButton_onClick()

    With objXFRequest
    ' -- set the Request Method to GET for the download
      .RequestMethod = "GET"
      .AddFile pathToFileOnClient, pathToFileOnServer
      .Start
    End With

  End Sub

  Sub objXFRequest_TransferComplete()

    With objArchive
      '-- Set ArchiveType for a *.zip file
      .ArchiveType = 1
      .OpenArchive(pathToFileOnClient)
      .ExtractPath = pathExtract
      .Extract
      .CloseArchive
    End With

    msgbox "The following file has been downloaded to: " &_
      pathToFileOnClient & ". " & _
      "Files have been extracted to: " & pathExtract & "."

  End Sub
</SCRIPT>
</BODY>
</HTML>
Created : 2/25/2004 1:38:24 PM (last modified : 2/27/2004 2:49:01 PM)
Rate this article!
 
Comments