Simultaneous Downloading of Multiple Files


At some point, you may need to download multiple files at the same time. This example shows how to download multiple files simultaneously using XFile.


Multi-file Download with SoftArtisans XFile

This example illustrates using XFile'sVisual (GUI) control. You'll find this useful in getting around browsers' usual limitation of downloading one file at a time.

For this example, we need two HTML files (SAXFileMultiDown.htm and AXFFileProgress.htm) and one ASP file (FormResp.asp). The first HTML file will contain our ActiveX control user interface, with which the user selects one or all the files to be downloaded. The other one allows us to view the progress of the download. The ASP file, named FormResp.asp, is where FileUp will take the request for the download and transfer the files from the server to the browser.

<%@ language="vbscript" %>

<html>
<head>
<title>Software Artisans SA-AXFile Download Sample</title>
<%
'--- Server name
httpHost = "localhost"

'--- Files to be downloaded
file1 = Server.URLEncode("boot.ini")
file2 = Server.URLEncode("config.sys")

%>
</head>
<body>
<p><strong><font color="black" size="5">SA-AXFile Download
Sample</font></strong></p>
<p></p>
<script language="javascript">

function startDownload() {
winStyle="Height=300,Width=400,Status=No,Toolbar=To,_       Menubar=No,Location=No";
window.open("AXFFileProgress.htm", "_blank", winStyle);
}

</script>

<object classid="CLSID:B82FA17C-F3A9-11D2-B5DD-0050041B7FF6"
id="AXFFileDownload" name="AXFFileDownload"
style="height: 200px; left: 0px; top: 0px; width: 400px"
viewastext>
</object>

<p><input id="Button1" name="Button1" type="button"
value="Start Download" onclick="startDownload()" /></p>

<script language="vbs">
Set XFile = AXFFileDownload.XFRequest

XFile.Server = <%=httpHost%>

AXFFileDownload.AddFile "C:\temp\boot.ini", _
"http://localhost/SAFileUpSamples/ClientDownload/MultiDownload" & _
"/FormResp.asp?" & "File=<%=File1%>"

AXFFileDownload.AddFile "C:\temp\config.sys", _
"http://localhost/SAFileUpSamples/ClientDownload/MultiDownload" & _
"/FormResp.asp?" & "File=<%=File2%>"

</script>

</body>
</html>

That's obviously a lot of information to take in at once so we'll cover the code one section at a time:

AXFFileProgress.htm is a much simpler file, but the most important. This page starts the download process. We are calling the XFile'sProgress object, in order to display the status of the transfer. We ensure that the progress control is displayed before the transfer starts. Otherwise, in the multi-threaded environment of Internet Explorer, a transfer could complete before the progress window is displayed, yielding an inconsistent user experience.

<html>
<head>
<title>Software Artisans SA-AXFile Download Progress</title>

<script language="javascript">
function callback()
{
document.getElementById("AXFFileProgress").XFRequestStream =
opener.document.getElementById("AXFFileDownload").XFRequestStream;
document.getElementById("AXFFileProgress").ShowProgress();
opener.document.getElementById("AXFFileDownload").Start();
window.close();
}

</script>
</head>
<body onload="callback();">
<object id="AXFFileProgress"
classid="CLSID:C3EAF164-E06A-11D2-B5C9-0050041B7FF6"></object>
</body>
</html>

The sections of this file work as follows:

The last page deals with the download via the server. This is where FileUp is used to direct where the source file is on the server. This has very little code, but you can imagine adding more sophisticated functions for authorizations, logging, and management of the download.

There is the major section:

<%

'--- Get the QueryString value to be used as the source file to be downloaded.
file = Request.QueryString("File")

'---
'--- Create an instance of the file download component
'---
Set download = Server.CreateObject("SoftArtisans.FileUp")


'--- The root path would be supplied for the source of the download.
'--- In this example it is hard coded.
download.TransferFile "C:\" & File

%>

FileUp requires only a single parameter: the full path of the file to be transferred to the server. In this example, both files are in the same folder. You could also use the Querystring to specify an ID or some other means of making the server filename hidden.
If the download is complete, you will see checkmark over files inside of the interface. You could also use the transfer complete method within the AXFFileProgress.htm for additional user interaction.

Top


Copyright © 2010 SoftArtisans, Inc. All rights reserved.