The iASP_FileUp component provides the facility to upload and downloadthe required files (which include plain text, docs, images and all binary data files) on the Server's hard disk. It consists of three parts:
The iASP's Server.CreateObject provides the facility to instantiate this component , after which all methods and properties can be accessed.
Method Signature: void
saveAs([in]String filename)
This method uploads the browsed file with the given filename on the Server.
The Path property can be set in order to save the file in the required directory. If the path property is not set, then the file(s) will be saved in the current working directory of the Server. Any relative path given in the filename argument shall get concatenated with the path property. It should be noticed that the path where a file is being uploaded should exist on the Server.
Example:
(for single file upload)
Html page:
<HTML> <HEAD>
<TITLE>File Upload via iASP_Fileup</TITLE>
</HEAD>
<BODY>
<form enctype="multipart/form-data" method="post" action="sample2.asp">
Enter filename to upload: <input type="file" name="file1"><br>
<input type="submit">
</form>
</BODY>
</HTML>
Script for 'sample2.asp':
<HTML><HEAD>
<TITLE>Upload File </TITLE>
</HEAD>
<BODY>
<% Set obj = Server.CreateObject("SoftArtisans.FileUp")
obj.Path= "c:\temp"
obj.saveAs "MyHtml.html" %><BR>
Thank you for uploading your file.
</BODY>
</HTML>
If multiple files are to be uploaded by a single request (i.e. by clicking the Submit button), then 'form' method is used. In this case, all the information related to files remain saved in the UploadDictionary object and the files can be accessed again with all their properties.
Example:
( for multiple files upload)
Script for 'sample2.asp':
<HTML><HEAD>
<TITLE>Uploading Multiple Files </TITLE>
</HEAD>
<BODY>
<% Set obj = Server.CreateObject("iASP_Fileup")
obj.form("file1").saveAs "MyHtml01.html"
obj.form("file2").saveAs "MyHtml02.html"
obj.form("file3").saveAs "MyHtml03.html"
<BR>
Thank you for uploading your file.
</BODY>
</HTML>
In case file of the same name already exists, 'saveAs' method overwrites it by default.
This method uploads the browsed file with the original filename on the Server.
The Path property can be set in order to save the file in the required directory. If the path property is not set, then the file(s) will be saved in the current working directory of the Server. Any relative path given in the filename argument shall get concatenated with the path property. It should be noticed that the path where a file is being uploaded should exist on the Server.
Example:
(for single file upload)
Html page:
<HTML> <HEAD>
<TITLE>File Upload via iASP_Fileup</TITLE>
</HEAD>
<BODY>
<form enctype="multipart/form-data" method="post" action="sample2.asp">
Enter filename to upload: <input type="file" name="file1"><br>
<input type="submit">
</form>
</BODY>
</HTML>
Script for 'sample2.asp':
<HTML><HEAD>
<TITLE>Upload File </TITLE>
</HEAD>
<BODY>
<% Set obj = Server.CreateObject("SoftArtisans.FileUp")
obj.Path= "c:\temp"
obj.save %><BR>
Thank you for uploading your file.
</BODY>
</HTML>
If multiple files are to be uploaded
by a single request (i.e. by clicking the Submit button), then 'form' method
is used. In this case, all the information related to files remain saved
in the UploadDictionary object and the files can be accessed again with
all their properties.
Example:
( for multiple files upload)
Script for 'sample2.asp':
<HTML><HEAD>
<TITLE>Uploading Multiple Files </TITLE>
</HEAD>
<BODY>
<% Set obj = Server.CreateObject("iASP_Fileup")
obj.Path= "c:\temp"
obj.form("file1").save
obj.form("file2").save
obj.form("file3").save
<BR>
Thank you for uploading your file.
</BODY>
</HTML>
In case file of the file having same name already exists, 'save' method overwrites it by default.
This method uploads the browsed file with the original filename on the Server's virtual directory as specified by the argument of the method. If no path is specified, the file is saved in the current working directory.
Example:
(for single file upload in Virtual
Directory)
Html page:
<HTML>
<HEAD>
<TITLE>File Upload via iASP_Fileup</TITLE>
</HEAD>
<BODY>
<form enctype="multipart/form-data" method="post" action="sample2.asp">
Enter filename to upload: <input type="file" name="file1"><br>
<input type="submit">
</form>
</BODY>
</HTML>
Script for 'sample2.asp':
<HTML><HEAD>
<TITLE>Upload File </TITLE>
</HEAD>
<BODY>
<% Set obj = Server.CreateObject("SoftArtisans.FileUp")
obj.saveInVirtual "c:\instant ASP\lib"
%><BR>
Thank you for uploading your file.
</BODY>
</HTML>
If multiple files are to be uploaded by a single request (i.e. by clicking the Submit button), then 'form' method is used. In this case, all the information related to files remain saved in the UploadDictionary object and the files can be accessed again with all their properties.
Example:
( for multiple files upload in
Virtual Directory)
Script for 'sample2.asp':
<HTML><HEAD>
<TITLE>Uploading Multiple Files </TITLE>
</HEAD>
<BODY>
<% Set obj = Server.CreateObject("SoftArtisans.FileUp")
obj.form("file1").saveInVirtual "c:\instant ASP\lib"
obj.form("file2").saveInVirtual "c:\instant ASP\lib"
obj.form("file3").saveInVirtual "c:\instant ASP\lib"
<BR>
Thank you for uploading your file.
</BODY>
</HTML>
In case file of the file having
same name already exists, 'saveInVirtual' method overwrites it by default.
This method saves the browsed file into the Database. The recordset must point to a valid ADO Field object.
For Microsoft SQL Server, the column should be 'image' type while for Microsoft Access, the column should be 'OLE Object'.
When saving into blob fields, the ADO Recordset's cursor type should be equal to 2 and lock type should be 3.
Example:
( for single file uploading in
database)
Html page:
<HTML> <HEAD>
<TITLE>Single File Save to the DataBase via iASP_Fileup</TITLE>
</HEAD>
<BODY>
<form enctype="multipart/form-data" method="post" action="sample3.asp">
Enter filename to upload: <input type="file" name="file1"><br>
<input type="submit">
</form>
</BODY>
</HTML>
Script for 'ScriptBlob.asp':
<HTML><HEAD>
<TITLE>Saving Single Files </TITLE>
</HEAD>
<BODY>
<%
Set obj = Server.CreateObject("SoftArtisans.FileUp")
Set rsBlob = Server.CreateObject("ADODB.RECORDSET")
rsBlob.Open "TableName", "DSN", 2, 3 ' Table Name, DatabaseSourceName,Cursor
Type, Lock Type
rsBlob.AddNew
obj.saveAsBlob rsBlob.Fields("columnNameOfTable")
rsBlob.Update
rsBlob.Close
Set rsBlob = Nothing
%>
<BR>
Thank you for uploading your file.
</BODY>
</HTML>
If multiple files are to be uploaded by a single request (i.e. by clicking the Submit button), then 'form' method is used. In this case, all the information related to files remain saved in the UploadDictionary object and the files can be accessed again with all their properties.
Example:
( for multiple files upload in
Database)
Script for direct 'ScriptBlob.asp':
<HTML><HEAD>
<TITLE>Saving Multiple Files </TITLE>
</HEAD>
<BODY>
<%
Set obj = Server.CreateObject("SoftArtisans.FileUp")
Set rsBlob = Server.CreateObject("ADODB.RECORDSET")
count=0
rsBlob.Open "TableName", "DSN", 2, 3 ' Table Name, DatabaseSourceName,Cursor
Type, Lock Type
rsBlob.AddNew
rsBlob.Fields("index").value = 1
obj.form("file1").saveAsBlob rsBlob.Fields("columnNameOfTable")
rsBlob.Update
rsBlob.AddNew
rsBlob.Fields("index").value = 2
obj.form("file2").saveAsBlob rsBlob.Fields("columnNameOfTable")
rsBlob.Update
rsBlob.Close
Set rsBlob = Nothing
%>
<BR>
Thank you for uploading your file.
</BODY>
</HTML>
This method downloads the requested file to the browser from the Server. The user must give fully qualified path name in the argument.
Example:
(for downloading a file)
<%
set obj = Server.CreateObject("SoftArtisans.FileUp")
obj.transferFile("c:\Program
Files\Instant ASP\index.html")
%>
This method downloads the requested file to the browser from the Database using iASP. The recordset must point to a valid ADO Field object.
For Microsoft SQL Server, the column should be 'image' type while for Microsoft Access, the column should be 'OLE Object'.
When reading from blob fields, the ADO Recordset's cursor type and lock type should be equal to 3.
Example:
Script of 'ScriptBlob.asp':
<HTML><HEAD>
<TITLE>Downloading from Database </TITLE>
</HEAD>
<BODY>
<%
Set obj = Server.CreateObject("SoftArtisans.FileUp")
Set rsBlob = Server.CreateObject("ADODB.RECORDSET")
rsBlob.Open "TableName", "DSN", 3 , 3 ' Table Name, DatabaseSourceName,Cursor
Type, Lock Type
rsBlob.MoveFirst
obj.TransferBlob rsBlob.Fields("columnNameOfTable")
%>
<BR>
Thank you for uploading your file.
</BODY>
</HTML>
This method deletes the last uploaded file on the Server. If any specific file is to be deleted, then the name of that file is passed in to the overloaded delete method . This method can be used to cancel the last upload.
Example:
(for deleting last uploaded file)
Script of 'LastUploadDelete.asp':
<HTML><HEAD>
<TITLE>Saving Multiple Files </TITLE>
</HEAD>
<BODY>
<% Set obj = Server.CreateObject("SoftArtisans.FileUp")
obj.save
obj.save
obj.save
obj.delete ' i.e. Cancelling the last upload
%>
<BR>
Thank you for uploading your file.
</BODY>
</HTML>
Example:
(for deleting specific file)
Script of 'SpecificDelete.asp':
<HTML><HEAD>
<TITLE>Saving Multiple Files </TITLE>
</HEAD>
<BODY>
<% Set obj = Server.CreateObject("SoftArtisans.FileUp")
obj.save
obj.save
obj.delete "c:\Program Files\Plus!\index.html"
obj.save
%>
<BR>
Thank you for uploading your file.
</BODY>
</HTML>
This method flushes the entire HTTP POST input stream. It is used to explicitly clear the input stream especially, when a file greater than MaxBytes is sent. In this case,the browser wants to send more data and in due course, invokes Network Error. This error is never displayed as the browser assumes that the request was never completed. Thus 'flush' method explicitly clears the input stream.
Example:
(for flushing the HTTP POST inputstream)
Script of 'flushSample.asp':
<HTML><HEAD>
<TITLE>Flushing Input Stream</TITLE>
</HEAD>
<BODY>
<% Set obj = Server.CreateObject("SoftArtisans.FileUp")
obj.save 'file greater than MaxBytes is uploaded
obj.flush 'clears the inputstream
%>
</BODY>
</HTML>
This is a Read-Only property. The MIME Content Type of the file (specified by the fieldName), is used to determine the contents of the file. If multiple files are uploaded, then the ContentType of each file can be got by calling obj.form("file1").ContentType for each file upload. If obj.ContentType is called, it will return the ContentType of the first uploaded file.
Example:
(getting ContentType for multiple
file upload)
<%
con1 = obj.form("file1").ContentType
con2 = obj.form("file2").ContentType
con3 = obj.form("file3").ContentType
%>
This is a Read-Only property. The MIME Content Disposition of the data should always be "form-data" when using a browser supporting RFC 1867 uploads. It is true for multiple file uploads also. If multiple files are uploaded, then the ContentDisposition of each file can be got by calling obj.form("file1").ContentDisposition for each file upload. If obj.ContentDisposition is called, it will return the ContentDisposition of the first uploaded file.
Example:
(getting ContentDisposition for
multiple file upload)
<%
disp1 = obj.form(
"file1").ContentDisposition
disp2 = obj.form(
"file2").ContentDisposition
%>
This is a Read/Write property. This property is used to set the destination path on the Server of the uploaded file. By default, the path is set to user current working directory.
Example:
(setting path for multiple files
upload)
Html page:
<HTML> <HEAD>
<TITLE>Multiple File Upload via iASP_Fileup</TITLE>
</HEAD>
<BODY>
<form enctype="multipart/form-data" method="post" action="sample2.asp">
Enter filename to upload: <input type="file" name="file1"><br>
Enter filename to upload: <input type="file" name="file2"><br>
Enter filename to upload: <input type="file" name="file3"><br>
<input type="submit">
</form>
</BODY>
</HTML>
Script for 'sample2.asp':
<HTML><HEAD>
<TITLE>Uploading Multiple Files </TITLE>
</HEAD>
<BODY>
<%
Set obj = Server.CreateObject("SoftArtisans.FileUp")
obj.Path= "c:\Program Files"
obj.form("file1").saveAs "MyHtml01.html"
obj.form("file2").save
obj.form("file3").save
%>
<BR>
Thank you for uploading your file.
</BODY>
</HTML>
In the above exampe, all the three
files are uploaded in the c:\Program Files. Once the path is set, all the
following files will be saved in the set path.
This is a Read-Only property. ServerName is the fully qualified path where the file is saved on the Server. If multiple files are uploaded, then the ServerName of each file can be retrieved by calling obj.form("file1").ServerName() for each file upload. If obj.ServerName() is called, it will return the ServerName of the first uploaded file.
Example:
(getting ServerName for multiple
file upload)
Html page:
<HTML> <HEAD>
<TITLE>Multiple File Upload via iASP_Fileup</TITLE>
</HEAD>
<BODY>
<form enctype="multipart/form-data" method="post" action="sample2.asp">
Enter filename to upload: <input type="file" name="file1"><br>
Enter filename to upload: <input type="file" name="file2"><br>
Enter filename to upload: <input type="file" name="file3"><br>
<input type="submit">
</form>
</BODY>
</HTML>
Script for 'sample2.asp':
<%
Set obj = Server.CreateObject("SoftArtisans.FileUp")
obj.save
obj.saveAs "MyHtml.html"
obj.saveInVirtual
server1 = obj.form("file1").ServerName
server2 = obj.form("file2").ServerName
server3 = obj.form("file3").ServerName
Response.Write server1
Response.Write server2
Response.Write server3
%>
This is a Read-Only property.
UserFileName is the fully qualified path of the file to be uploaded (according
to the user's directory structure). If multiple files are uploaded, then
the UserFileName of each file can be retrieved by calling obj.form("file1").UserFileName()
for each file upload. If obj.UserFileName() is called, it will return the
UserFileName of the first uploaded file.
Example:
(getting UserFileName for multiple
file upload)
Html page:
<HTML> <HEAD>
<TITLE>Multiple File Upload via iASP_Fileup</TITLE>
</HEAD>
<BODY>
<form enctype="multipart/form-data" method="post" action="sample2.asp">
Enter filename to upload: <input type="file" name="file1"><br>
Enter filename to upload: <input type="file" name="file2"><br>
Enter filename to upload: <input type="file" name="file3"><br>
<input type="submit">
</form>
</BODY>
</HTML>
Script for 'sample2.asp':
<%
Set obj = Server.CreateObject("SoftArtisans.FileUp")
obj.form("file1").save
obj.form("file2").saveAs "MyHtml.html"
obj.form("file3").saveInVirtual "c:\instant ASP\lib"
user1 = obj.form("file1").UserFileName
user2 = obj.form("file2").UserFileName
user3 = obj.form("file3").UserFileName
Response.Write user1
Response.Write user2
Response.Write user3
%>
This is a Read-Only property. Count property returns the total number of components present on the Form.
Example:
(for retrieving count )
Script for 'sample2.asp':
<%
Set obj = Server.CreateObject("SoftArtisans.FileUp")
count=obj.Count
Response.Write count
%>
This is a Read/Write property. MaxBytes determines the maximum number of bytes of file which are to be transferred to the Server. If a file greater in size than MaxBytes is uploaded, then only MaxBytes are transferred.
Example:
(for setting maximum bytes )
Script for 'maxbytesSample.asp':
<%
Set obj = Server.CreateObject("SoftArtisans.FileUp")
obj.MaxBytes= 1024*1024 ' i.e. 1MB
obj.form("file1").save ' file greater than 1MB shall
be truncated
obj.MaxBytes= 1024 ' i.e. 1KB
obj.form("file2").saveAs "MyHtml.html"
obj.MaxBytes= 1024*4 ' i.e. 4KB
obj.form("file3").saveInVirtual "c:\instant ASP\lib"
%>
This is a Read-Only property.
TotalBytes determines the total number of bytes transferred to the Server.
If multiple files are uploaded,
then the TotalBytes of each file can be retrieved by calling obj.form("file1").TotalBytes()
for each file upload. If obj.TotalBytes() is called, it will return the
TotalBytes of the first uploaded file.
Example:
(for getting total bytes )
Script for 'totalbytesSample.asp':
<%
Set obj = Server.CreateObject("SoftArtisans.FileUp")
obj.form("file1").save
total1=obj.form("file1").TotalBytes
obj.form("file2").saveAs "MyHtml.html"
total2=obj.form("file2").TotalBytes
obj.form("file3").saveInVirtual "c:\instant ASP\lib"
total3=obj.form("file3").TotalBytes
Response.Write total1
Response.Write total2
Response.Write total3
%>
This is a Read/Write property. With the help of this property, the overwriting of any file can be controlled. By default, it is set true i.e. any file having the name of an uploaded file will be overwritten.
Example:
(for overwriting files)
Script for 'overwriteSample.asp':
<%
Set obj = Server.CreateObject("SoftArtisans.FileUp")
ow=obj.OverWriteFiles
if ow = true then
obj.OverWriteFiles = false
end if
obj.form("file1").save ' if the file already exists,
then it will not be over written during upload
%>
This is a Read-Only property. IsEmpty property shows whether the file uploaded contained data or not.
Example:
(for checking empty files)
Script for 'isemptySample.asp':
<%
Set obj = Server.CreateObject("SoftArtisans.FileUp")
obj.form("file1").save
empty=obj.form("file1").IsEmpty
if empty = true then
Response.Write "The file uploaded was empty"
else
Response.Write "The file uploaded contains data"
end if
%>
This is a Read-Only property. Error returns true or false depending upon whether the current task is successfully completed or not.
Example:
(for eveluating Error value)
Script for 'isemptySample.asp':
<%
Set obj = Server.CreateObject("SoftArtisans.FileUp")
obj.form("file1").save
err1=obj.Error
if err1 = false then
Response.Write "The file is uploaded successfully"
else
Response.Write "Error in uploading the file"
end if
%>
This is the key method which returns the object of UploadDictionary which holds all the information about the form elements and the files. It not only works similar to ASP's Request.Form but it can be used to access the file properties and methods in case of multiple uploads.
Example:
(accessing fields of the 'form'
for multiple files upload)
Html page:
<HTML> <HEAD>
<TITLE>Multiple File Upload via iASP_Fileup</TITLE>
</HEAD>
<BODY>
<form enctype="multipart/form-data" method="post" action="sample2.asp">
Enter Path1:<input name="f1"><br>
Enter filename to upload: <input type="file" name="file1"><br>
Enter filename to upload: <input type="file" name="file2"><br>
<input type="submit">
</form>
</BODY>
</HTML>
Script for 'sample2.asp':
<HTML><HEAD>
<TITLE>Accessing Form Fields </TITLE>
</HEAD>
<BODY>
<%
Set obj = Server.CreateObject("SoftArtisans.FileUp")
path1 = obj.form("f1").Item 'and not obj.form("f1")
obj.Path = path1
obj.save
obj.saveAs "MyHtml01.html"
%>
<BR>
Thank you for uploading your file.
</BODY>
</HTML>
In the above example, the user
enters the path name into the text field. The user can get this value by
the obj.form(fieldname).Item method (and not by obj.form(fieldname) )
the browsed file can then be uploaded to the specified path by 'saveAs'
method.
This is a Read-Only property. DateLastModified determines the last modified date of the last uploaded file. The date is displayed in the Local Time Zone.
It works if the client browser sends this information. ( Internet Explorer and Netscape Navigator do not send this infomation in the request ).
Example:
(getting DateLastModified for
single file upload)
Html page:
<HTML> <HEAD>
<TITLE>Single File Upload via iASP_Fileup</TITLE>
</HEAD>
<BODY>
<form enctype="multipart/form-data" method="post" action="sample2.asp">
Enter filename to upload: <input type="file" name="file1"><br>
<input type="submit">
</form>
</BODY>
</HTML>
Script for 'sample2.asp':
<%
Set obj = Server.CreateObject("SoftArtisans.FileUp")
oj.form("file1").save
dt = obj.DateLastModified
Response.Write dt 'will return, say, Sat May 29
11:40:42 GMT 1999
%>
This is a Read-Only property. DateLastModifiedUTC determines the last modified date of the last uploaded file. The date is displayed in the Universal Time (UTC or GMT).
It works if the client browser sends this information. ( Internet Explorer and Netscape Navigator do not send this infomation in the request ).
Example:
(getting DateLastModifiedUTC
for single file upload)
Html page:
<HTML> <HEAD>
<TITLE>Single File Upload via iASP_Fileup</TITLE>
</HEAD>
<BODY>
<form enctype="multipart/form-data" method="post" action="sample2.asp">
Enter filename to upload: <input type="file" name="file1"><br>
<input type="submit">
</form>
</BODY>
</HTML>
Script for 'sample2.asp':
<%
Set obj = Server.CreateObject("SoftArtisans.FileUp")
oj.form("file1").save
dtUTC = obj.DateLastModifiedUTC
Response.Write dtUTC 'will return, say, Sat May
29 11:40:42 GMT 1999
%>
This is a Read/Write property. UseDateLastModified determines whether the last uploaded file will hold the last modified date of the user's original file on the Server or not. By default , this property is set false.
It works if the client browser sends this information. ( Internet Explorer and Netscape Navigator do not send this infomation in the request ).
Script for 'sample2.asp':
<%
Set obj = Server.CreateObject("SoftArtisans.FileUp")
obj.UseDateLastModified=true
oj.form("file1").save 'saved with user's original file
date
%>
Back to iASP_Fileup
Back to Methods Back
to Properties SAFile
UploadDictionary
© 1999, Halcyon Software,Inc® . All Rights Reserved.