Directory Upload - Using Client-Side Controls

SA-FileUp now has the capability to upload a full directory and any subdirectories. You can do so, using SA-FileUp in combination with client-side components, SA-XFile and SA-JFile.

You use methods specific to the client-side component on the initial page of the upload application, as shown in the following examples.

Step 1: Do a recursive upload.

Using SA-JFile
Use addDirectoryRecursive() to do a recursive upload. For example:

<SCRIPT LANGUAGE="Javascript">
	<!--
	
function myTransferProgress()  //* this is the function fired on the load of the page
	
	{
		//--- In Javascript, you must use "\\" to stand for "\" character
		
		//--- Add Full Directory using recursive method
		fileupload.addDirectoryRecursive("C:\\Temp\\Download")
		
	
	
	//-->
</SCRIPT>

Using SA-XFile
Use addDirectoryRecursive() to do a recursive upload. For example:


....

<SCRIPT LANGUAGE="VBSCRIPT">
Sub UploadButton_onClick()

	'-- Set the URL where we want to send the data by
	'-- using the CurrentURL property
    SAXFile.CurrentURL = "Http://localhost/SAFileUp3Samples/Recursive/Xfile/ResurXfileResp.asp"

	'--- Add Directory and subdirectory with all files
	SAXFile.AddDirectoryRecursive("c:\temp\download") 
	
	' -- start the transfer
	SAXFile.Start

end Sub
</Script>
.....

Step 2: On the Form Action that uses SA-FileUp, use SaveRecursive() instead of Save or SaveAs. With this code, you retain the original filenames.

The following code shows what your response page looks like:

<%
'---
'--- Create an instance of SA-FileUp
'---
Set upl = Server.CreateObject("SoftArtisans.FileUp")

upl.Path = "D:\Uploads"

'--- Save full directory of files
upl.SaveRecursive() 
%>

Step 3: If you plan to display the properties of the uploaded file when the transfer is complete, code your page as if you were uploading multiple files. For example:

<table WIDTH="95%" BORDER="1" CELLSPACING="2" CELLPADDING="0" HEIGHT="206">
<tr>
<th COLSPAN="2"><p><center>Contents of The Form</center></th></tr>
<tr>
<th WIDTH="20%"><p><center>Tag Name</center></th>
<th WIDTH="80%"><p><center>Value</center></th></tr>
<%
for each item in upl.form
		response.write("<TR><TD ALIGN=""RIGHT"">" & item & "</TD>")
		if Not IsObject(upl.form(item)) Then
			'---
			'--- This is a regular (non-file) form element. Show its value
			'---
			response.write("<TD>" & upl.form(item) & "</TD></TR>")
		Else
		'--- 
		'--- This is a form element. Show all the details
		'---
%>
<td>

<table WIDTH="100%" BORDER="1" CELLSPACING="2" CELLPADDING="0" HEIGHT="206">
	<tr>
	<th COLSPAN="2"><p><center>File Details</center></th></tr>
	<tr>
	<th WIDTH="35%"><p><center>Item</center></th>
	<th WIDTH="65%"><p><center>Value</center></th></tr>
	<tr>
	<td WIDTH="35%" ALIGN="RIGHT" VALIGN="TOP"> Server filename</td>
	<td WIDTH="65%"><%=upl.Form(item).ServerName%> </td></tr>
	<tr>
	<td WIDTH="35%" ALIGN="RIGHT" VALIGN="TOP"> User's filename</td>
	<td WIDTH="65%"><%=upl.Form(item).UserFilename%> </td></tr>
	'
</table>
</td></tr>
<% 
	End If
next %>

For more examples, check out the samples provided as part of the SA-FileUp distribution. See Programmer's Samples for a list of the contents of the Samples directory.

 

Previous Page Next Page