This class serves the general purpose functions of the file. This
class can be instantiated independent to the FileUp
and its functions can be invoked even when there is no upload in progress.
<% Set obj= Server.CreateObject("SoftArtisans.SAFile")
%>
Methods
Properties
Method Descriptions
Method Signature: void create([in]String
fullyQualifiedFilename)
This method creates the required file on the Server. The filename should
be given with fully qualified path, otherwise the file is created in the
default directory ( here the user's current working directory). If the
file of the same name already exists, then 'create' method overwrites
it.
File creation example
<HTML><HEAD>
<TITLE>Upload File </TITLE>
</HEAD>
<BODY>
<%
Set obj = Server.CreateObject("SoftArtisans.SAFile")
obj.create "\MyFolder1\MyFolder2\MyHtml.html"
obj.Path= "c:\program files\plus!"
obj.create "MyHtml.html"
%>
<BR>
Thank you for uploading your file.
</BODY>
</HTML>
Method Signature: void createtemp()
This method creates the temporary file on the Server. By default
the files are created in the current user's working directory. The path
property can be used to create these files in the desired directory. The
temporary files aquire the names Iasp_#1.tmp, Iasp_#2.tmp, Iasp_#3.tmp
and so on.
Creating temporary files
<HTML><HEAD>
<TITLE>Upload File </TITLE>
</HEAD>
<BODY>
<%
Set obj = Server.CreateObject("SoftArtisans.SAFile")
obj.createTemp
obj.createTemp
obj.Path= "c:\program files"
obj.createTemp
%>
<BR>
Thank you for uploading your file.
</BODY>
</HTML>
The above program creates two temporary files in the current working
directory and the third temporary file in the desired directory.
Method Signature: void saveAs([in]String
filename)
This method uploads the browsed file with the given filename on
the Server. 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.
Single file upload example
HTML
<HTML> <HEAD>
<TITLE>File Upload via SAFile</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
<HTML><HEAD>
<TITLE>Upload File </TITLE>
</HEAD>
<BODY>
<% Set obj = Server.CreateObject("SoftArtisans.SAFile")
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.
Multiple file upload example
<HTML><HEAD>
<TITLE>Uploading Multiple Files </TITLE>
</HEAD>
<BODY>
<% Set obj = Server.CreateObject("SoftArtisans.SAFile")
obj.Path= "c:\temp"
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.
Method Signature: void save()
This method uploads the browsed file with the original filename
on the Server.
Single file upload example
HTML
<HTML> <HEAD>
<TITLE>File Upload via SAFile</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
<HTML><HEAD>
<TITLE>Upload File </TITLE>
</HEAD>
<BODY>
<% Set obj = Server.CreateObject("SoftArtisans.SAFile")
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.
Multiple file upload example
<HTML><HEAD>
<TITLE>Uploading Multiple Files via SAFile</TITLE>
</HEAD>
<BODY>
<% Set obj = Server.CreateObject("SoftArtisans.SAFile")
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 similar name already exists, 'save' method
overwrites it.
Method Signature: void saveInVirtual()
This method uploads the browsed file with the original filename
on the Server's virtual directory.
Single file upload to a virtual directory
HTML
<HTML> <HEAD>
<TITLE>File Upload via SAFile</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
<HTML><HEAD>
<TITLE>Upload File </TITLE>
</HEAD>
<BODY>
<% Set obj = Server.CreateObject("SoftArtisans.SAFile")
obj.saveInVirtual %>
<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.
Multiple file upload to a virtual directory
<HTML><HEAD>
<TITLE>Uploading Multiple Files via SAFile</TITLE>
</HEAD>
<BODY>
<% Set obj = Server.CreateObject("SoftArtisans.SAFile")
obj.form("file1").saveInVirtual
obj.form("file2").saveInVirtual
obj.form("file3").saveInVirtual %>
<BR>
Thank you for uploading your file.
</BODY>
</HTML>
In case file of the file having next name already exists, 'saveInVirtual'
method overwrites it by default.
Method Signature: void saveAsBlob([in]
ADODB.FIELD columnNameOfTable)
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.
Uploading a single file to a database
HTML
<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
<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.
Uploading multiple files to a database
<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>
Method Signature: void delete()
Method Signature: void delete([in]String filename)
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.
Deleting the last uploaded file
<HTML><HEAD>
<TITLE>Saving Multiple Files via SAFile</TITLE>
</HEAD>
<BODY>
<%
Set obj= Server.CreateObject("SoftArtisans.SAFile")
obj.save
obj.save
obj.save
obj.delete
%>
<BR>
Thank you for uploading your file.
</BODY>
</HTML>
Deleting a specific file
<HTML><HEAD>
<TITLE>Saving Multiple Files via SAFile</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>
Method Signature: void flush()
This method flushes the entire HTTP POST input stream. This method 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 the
'flush' method can be used to explicitly clear the input stream.
Flushing the HTTP POST input stream
<HTML><HEAD>
<TITLE>Flushing Input Stream via SAFile</TITLE>
</HEAD>
<BODY>
<%
Set obj= Server.CreateObject("SoftArtisans.SAFile")
obj.save
obj.flush
%>
</BODY>
</HTML>
Property descriptions
Property Name: ContentType
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.
Retrieving ContentType for a multiple file upload
<%
con1 = obj.form("file1").ContentType
con2 = obj.form("file2").ContentType
con3 = obj.form("file3").ContentType
%>
Property Name: ContentDisposition
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.
Retrieving ContentDisposition for a multiple file upload
<%
disp1 = obj.form( "file1").ContentDisposition
disp2 = obj.form( "file2").ContentDisposition
%>
Property Name: Path
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.
Setting the path for a multiple file upload
HTML
<HTML> <HEAD>
<TITLE>Multiple File Upload via SAFile</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
<HTML><HEAD>
<TITLE>Uploading Multiple Files </TITLE>
</HEAD>
<BODY>
<%
Set obj= Server.CreateObject("SoftArtisans.SAFile")
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.
Property Name: ServerName
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 got 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.
Retrieving the ServerName for a multiple file upload
HTML
<HTML> <HEAD>
<TITLE>Multiple File Upload via SAFile</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
<%
Set obj= Server.CreateObject("SoftArtisans.SAFile")
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
%>
Property Name: UserFileName
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 got by calling obj.form("file1").UserFileName for each file upload.
If obj.UserFileName is called, it will return the UserFileName of the
last uploaded file.
Retrieving UserFileName for a multiple file upload
HTML
<HTML> <HEAD>
<TITLE>Multiple File Upload via SAFile</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
<%
Set obj= Server.CreateObject("SoftArtisans.SAFile")
obj.form("file1").save
obj.form("file2").saveAs "MyHtml.html"
obj.form("file3").saveInVirtual
user1 = obj.form("file1").UserFileName
user2 = obj.form("file2").UserFileName
user3 = obj.form("file3").UserFileName
Response.Write user1
Response.Write user2
Response.Write user3
%>
Property Name: Count
This is a Read-Only property. Count returns the total number of components
present on the Form.
Retrieving the total number form components using Count
<%
Set obj= Server.CreateObject("SoftArtisans.SAFile")
count=obj.Count
Response.Write count
%>
Property Name: MaxBytes
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.
Setting the MaxBytes property
<%
Set obj= Server.CreateObject("SoftArtisans.SAFile")
obj.MaxBytes =1024*1024
obj.form("file1").save
obj.MaxBytes =1024
obj.form("file2").saveAs "MyHtml.html"
obj.MaxBytes =1024*4
obj.form("file3").saveInVirtual
%>
Property Name: TotalBytes
This is a Read-Only property. TotalBytes determines the total number
of bytes transferred to the Server.
Retrieving the total number of bytes transferred to the server
<%
Set obj = Server.CreateObject("SoftArtisans.SAFile")
obj.form("file1").save
total1=obj.TotalBytes
obj.form("file2").saveAs "MyHtml.html"
total2=obj.TotalBytes
obj.form("file3").saveInVirtual
total3=obj.TotalBytes
Response.Write total1
Response.Write total2
Response.Write total3
%>
Property Name: OverWriteFiles
This is a Read/Write property. With the help of this property, the overwriting
of any file can be controlled. By default, it set true i.e. any file having
the name of an uploaded file shall be overwritten.
Using the OverWriteFiles property
<%
Set obj = Server.CreateObject("SoftArtisans.SAFile")
ow=obj.OverWriteFiles
if ow = true then
obj.OverWriteFiles= false
end if
obj.form("file1").save
%>
Property Name: IsEmpty
This is a Read-Only property. IsEmpty property shows whether the file
uploaded contained data or not.
Using the IsEmpty property
<%
Set obj = Server.CreateObject("SoftArtisans.SAFile")
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
%>
Property Name: Error
This is a Read-Only property. Error returns true or false depending upon
whether the current task is successfully completed or not.
Evaluating the Error property
<%
Set obj = Server.CreateObject("SoftArtisans.SAFile")
obj.form("file1").save
err=obj.Error
if err = true then
Response.Write "The file is uploaded
successfully"
else
Response.Write "Error in uploading
the file"
end if
%>
Property Name: Form
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.
Accessing form fields for a multiple file upload
HTML
<HTML> <HEAD>
<TITLE>Multiple File Upload via SAFile</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 Path2:<input name="f2"><br>
Enter filename to upload: <input type="file" name="file2"><br>
<input type="submit">
</form>
</BODY>
</HTML>
Script
<HTML><HEAD>
<TITLE>Accessing Form Fields </TITLE>
</HEAD>
<BODY>
<%
Set obj = Server.CreateObject("SoftArtisans.SAFile")
path1 = obj.form("f1").Item
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.
Property Name: DateLastModified
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
).
Retrieving DateLastModified for a single file upload
HTML
<HTML> <HEAD>
<TITLE>Multiple File Upload via SAFile</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
<%
Set obj = Server.CreateObject("SoftArtisans.SAFile")
oj.form("file1").save
dt = obj.DateLastModified
Response.Write dt
%>
Property Name: DateLastModifiedUTC
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 ).
Retrieving DateLastModifiedUTC for a single file upload
HTML
<HTML> <HEAD>
<TITLE>Multiple File Upload via SAFile</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
<%
Set obj = Server.CreateObject("SoftArtisans.SAFile")
oj.form("file1").save
dtUTC = obj.DateLastModifiedUTC
Response.Write dtUTC
%>
Property Name: UseDateLastModified
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
).
UseDateLastModified example
<%
Set obj = Server.CreateObject("SoftArtisans.SAFile")
obj.UseDateLastModified= true
oj.form("file1").save
%>
Property Name: MIMEVersion
This is a Read-Only property. MIMEVer contains the MIME version
of the file uploaded. This property works if the client browser sends
this information. ( Internet Explorer and Netscape Navigator do not send
this infomation in the request ).
Checking the MIME type of uploaded files
<%
Set obj = Server.CreateObject("SoftArtisans.SAFile")
obj.form("file1").save
obj.form("file2").save
Response.Write obj.form("file1").MIMEVersion
Response.Write obj.form("file2").MIMEVersion
%>
If you require technical support please send complete details about the
problem you are having to support@halcyonsoft.com.
|