Downloading with the ActiveX Control


The ActiveX download control displays the URL of the file to download, and the local download destination. The ActiveX control can be used from Internet Explorer or Visual Basic, and includes an accurate progress indicator that allows the user to monitor the progress of the download.

To download with XFile's ActiveX download control, create an instance of the AXFFileDownload object.
Exercise: Downloading with the ActiveX Control in Internet Explorer
We will script a simple, two-file download, using XFile's ActiveX download control and its progress indicator. We will create two scripts: AXFFile_download.htm and AXFFileProgress.htm. The first will create an instance of the ActiveX download object (AXFFileDownload), and the second will create an instance of the progress indicator object(AXFFileProgress).
XFile's ActiveX Download Control
  1. Create an HTML document containing the following lines of script. Name the file AXFFile_download.htm.
    <!-- Create a function that will open the progress indicator window. --><SCRIPT>
            function	StartDownload() {
            winstyle="height=300,width=400,status=no,toolbar=no,menubar=no,location=no";
            window.open("AXFFileProgress.htm",null,winstyle);
            }
            </SCRIPT>
    
            <!-- Create an instance of the ActiveX download control  (the AXFFileDownload object),
              and assign values to its properties. -->
            <OBJECT classid="CLSID:B82FA17C-F3A9-11D2-B5DD-0050041B7FF6" codebase="/SAXFileSamples/saxfile.cab"
            height="200" id="AXFFileDownload" style="HEIGHT: 200px; LEFT: 0px; TOP: 0px; WIDTH: 400px"
            width="400" VIEWASTEXT>
            <PARAM NAME="_cx" VALUE="10583">
            <PARAM NAME="_cy" VALUE="5292">
            <PARAM NAME="Appearance" VALUE="0">
            <PARAM NAME="BackColor" VALUE="16777215">
            <PARAM NAME="ForeColor" VALUE="0">
            </OBJECT>
    
            <!-- Create a download button that will call the StartDownload() function when clicked. --><INPUT id=button1 name=button1 type=button value="Start Download" onclick = "startdownload()">
    
            <script language="vbs">
    
            '--- Create an instance of the XFRequest object.
            set xfile = AXFFileDownload.XFRequest
    
            '--- Set files to download.  AXFFileDownload.AddFile takes two parameters: the first is the download
            '--- destination path and file name, and the second is the URL of the file to download.
            AXFFileDownload.AddFile "c:\testone.txt", "http://localhost/saxfilesamples/vb/download/readme.txt"
            AXFFileDownload.AddFile "c:\testone.htm", "http://localhost/saxfilesamples/default.htm"
    
            </script>
          
  2. Create an HTML document containing the following lines of script. Name the file AXFFileProgress.htm. Save AXFFile_download.htm and AXFFileProgress.htm in the same directory.
    <!-- Create a CallBack procedure that will execute when AXFFileProgress.htm is loaded.  The CallBack
              procedure synchronizes the ActiveX control and its progress indicator, and initiates both. -->
            <SCRIPT language="VBS">
            Sub Callback()
    
            '--- Assign the value of AXFFileDownload's XFRequestStream property to AXFFileProgress's
            '--- XFRequestStream property.  The AXFFileDownload object represents the ActiveX control,
            '--- and the AXFFileProgress object represents the progress indicator.
            document.all("AXFFileProgress").XFRequestStream =  opener.document.all("AXFFileDownload").XFRequestStream
    
            '--- Start the progress indicator.
            document.all("AXFFileProgress").ShowProgress
    
            '--- Start the file transfer.
            opener.document.all("AXFFileDownload").Start
    
            '--- Close the progress window when the transfer is complete (that is, when the Start method
            '--- stops executing).
            window.close
    
            End Sub
            </SCRIPT>
    
            <!-- Execute the Callback procedure when AXFFileProgress.htm loads.--><BODY onload="Callback()">
    
            <!-- Create an instance of the AXFFileProgress object (the ActiveX control's
              progress indicator). -->
            <OBJECT ID="AXFFileProgress" CLASSID="CLSID:C3EAF164-E06A-11D2-B5C9-0050041B7FF6"></OBJECT>
    
            <!-- Display a message box when the transfer is complete.  This will not work in Javascript. --><SCRIPT language = vbs>
            'This will not work in Javascript
            sub AXFFileProgress_TransferComplete()
            MsgBox "Transfer completed"
            end sub
            </SCRIPT>
          
Understanding the Script

Copyright © 2010 SoftArtisans, Inc. All rights reserved.