Methods
Compare
Compare Name
Performs a binary comparison of the file object with the one specified by the Name
parameter and returns True if the files are the same.
| Parameter |
Description |
| Name |
String
containing the path for the file to be compared. |
Returns: A boolean indicating if the files are identical
Notes: The Compare method is useful for determining if two files are
identical.
Example: The following example compares file1.txt and file2.txt:
Set File = Server.CreateObject("ActiveFile.File")
File.Name = "C:\file1.txt"
If File.Compare("C:\file2.txt") Then
Response.Write "Files are identical<BR>"
Else
Response.Write "Files do not match<BR>"
End If
See Also: File.Name property
Copy Name
Copies the file to the target file specified by Name.
| Parameter |
Description |
| Name |
String
containing the Target path for the Copy
operation. |
Returns: A File object referencing the target file.
Notes: The Copy method allows you to make a copy of the file currently
being referenced by the File object. The return value can be used to access the new file
while the old File object still references the original file.
 |
If the target file specified by Name parameter already exists, it is
overwritten. |
Example: The following example copies file1.zip and file2.zip:
Set File1 = Server.CreateObject("ActiveFile.File")
File1.Name = "C:\file1.zip"
Set File2 = File1.Copy("C:\file2.txt")
Create Name
Creates a new file.
| Parameter |
Description |
| Name |
String
containing the path for the new file. |
Returns: Nothing
Notes: The Create method allows you to create a zero length file
specified by the Name parameter.
 |
If the file specified by Name parameter already exists, it is overwritten
with an empty file. |
Example: The following example shows how to create a new file:
Set File = Server.CreateObject("ActiveFile.File")
File.Create "C:\myfile.doc"
See Also: File.CreateTemp method
CreateTemp Path
Creates a temporary file in the directory/folder specified by Path.
| Parameter |
Description |
| Path |
String
containing the directory or folder path that will
contain the temporary file. |
Returns: Nothing
Notes: The CreateTemp method creates a temporary file with a unique
name in the directory specified by the Path parameter. The directory must already exist.
Example: The following example shows how to create a temporary file:
Set File = Server.CreateObject("ActiveFile.File")
File.CreateTemp "C:\temp"
See Also: File.Create method
Deletes the file associated with the File object.
Returns: Nothing
Notes: The Delete method allows you to permanently remove a file from the
file system. If the File object is referencing a directory, the directory will be deleted
only if it is empty. See the Directory.Delete
method for deleting non-empty directories.
 |
There is no undelete; once a file is deleted using this method, it can not
be restored. |
Example: The following example shows how to delete a file:
' Code showing initialization of the file object omitted
File.Delete
See Also: Directory.Delete
method
Download {Mimetype},{ModDate},{ResponseEnd},{DeleteFile}
Downloads a file to the client.
| Parameter |
Description |
| Mimetype |
Optional
string overriding the current Mimetype of the file. |
| ModDate |
Optional
date specifying what date should be specified in the HTTP Last-Modified header.
Defaults to the LastModified property. |
| ResponseEnd |
Optional
boolean to automatically end the response once the file has been downloaded. If you
are experiencing script timeout problems try using this flag. |
| DeleteFile |
Optional
boolean to delete the file being downloaded after successful download. |
Returns: True if downloading the file was successful. Any error,
or if the client disconnects while downloading the file will return false.
Notes: The File.Download method allows you to send the file referenced
by the File object as an HTTP response. This method is useful for controlling how files
from the server are sent to clients. The MimeType parameter specifies the value to use to
identify the content type of the file for the HTTP response. If the Mimetype parameter is
omitted, the MimeType property is used.
 |
If your Active Server Page contains any HTML tags or
Response.Write calls, steps need to be taken to ensure that only the contents of the file
are sent to the client. One way to eliminate extraneous HTML tags from your response is to
follow these steps:
- Set Response.Buffer = True at the beginning of your page
- Call Response.Clear prior to calling File.Download
- Call Response.End as soon as you have finished processing the file or set
the ResponseEnd parameter to True.
|
In addition to sending the contents of the file to the client, File.Download also sets
the HTTP Last-Modified header to indicate when the file was last modified. This allows
both browser client caching and proxy server caching to be supported by recognizing and
responding appropriately to HTTP requests that contain the If-Modified-Since header.
Depending on your application, you can use the ModDate parameter to control
whether or not cached versions of the downloaded file are used as follows.
- If you are downloading a permanent file, caching will automatically be based on the LastModified property of the file. In this case
you do not need to specify a ModDate parameter if you want caching to work.
- If you are downloading a temporary file that was created on the fly, you will need to
set the ModDate parameter to an appropriate value if you want caching to work.
For instance, if you are downloading a file exported from a database, you may want to set
the ModDate parameter to a date stored in the database record that represents
when the database record was last updated.
- To effectively disable caching, simply specify Now() as the ModDate parameter
An added bonus to supporting caching in your application is support for restarting
downloads. In the past, if a client's network connection was lost during the download of a
large file, the client would have to start the download all over again. Today's browsers
are now capable of picking up right where they left off. To support this, File.Download
will send only the portion of the file that was not yet downloaded instead of sending the
entire file.
Example: The following example shows how to download a file to a
browser:
' Code showing initialization of File object omitted
File.Download
See Also: Downloading a file from the server
Exists
Returns true if the file exists.
Returns: A boolean indicating whether the file exists or not.
Notes: The Exists method is useful for checking for the
existence of a file.
Example: The following example shows how to test to see if a file
exists:
' Code showing initialization of the File object omitted
If File.Exists Then
Response.Write "File exists.<BR>"
Else
Response.Write "File does not exist.<BR>"
End If
See Also: Directory.Exists
method
Export adoFieldObj, Append
Exports the Active Data Object (ADO) Field Object into the file.
| Parameter |
Description |
| adoFieldObj |
An ADO
field object of type long binary. |
| Append |
Boolean
flag indicating whether data should be appended to an existing file. |
Returns: Nothing
Notes: The Export method allows you to export files stored in
databases that support ADO and BLOB data types. The adoFieldObj parameter must point to
column of type adLongVarBinary of an existing row of an ADO RecordSet. After calling
Export, the file pointed to by the File object will contain the data from the database.
 |
If the File object points to a file that already exists and the Append
parameter is omitted or specified as False, Export will overwrite the file contents. |
Example: The following example shows how to export a file from a
database:
' Code showing initialization of File object and ADO RecordSet object omitted
File.Export Rs.Fields("BLOB")
See Also: Importing and exporting
files from a database
Import adoFieldObj
Imports the file into an Active Data Object (ADO) Field Object.
| Parameter |
Description |
| adoFieldObj |
An ADO
field object of type long binary. |
Returns: Nothing
Notes: The Import method allows you to store files in databases that
support ADO and BLOB data types. The adoFieldObj parameter must point to a column of type
adLongVarBinary of an existing row of an updateable ADO RecordSet. After calling Import,
the Update method of the ADO RecordSet object must be called to complete the update.
Example: The following example shows how to import a file into a
database:
' Code showing initialization of File object and ADO RecordSet object omitted
File.Import Rs.Fields("BLOB")
See Also: Importing and exporting
files from a database
IsDirectory
IsDirectory
Returns true if the file is a directory.
Returns: A boolean indicating whether the file is a directory.
Notes: This feature is provided for compatibility with version
1.x of ActiveFile. Use the Attributes
property for future compatibility.
IsReadonly
Returns true if the file is read-only.
Returns: A boolean indicating whether the file is read-only or not.
Notes: This feature is provided for compatibility with version
1.x of ActiveFile. Use the Attributes
property for future compatibility.
Refresh
Refreshes the attributes of a file object.
Returns: Nothing
Notes: Refresh should be used if the underlying file has been
changed by another component or external process.
Example: The following example shows how to refresh the File object:
' Code showing initialization of the File object omitted
File.Refresh
RegisterDll
Registers the DLL pointed to by the File object in the registry.
Returns: Nothing
Notes: RegisterDll will install self-registering DLLs in the
registry. The process must have write access to the registry. For more
information see Security Considerations.
Example: The following example shows how to register a DLL:
Set File = Server.CreateObject("ActiveFile.File")
File.Name = "C:\WINNT\system32\mycomp.dll"
File.RegisterDll
See Also: File.Name property
Rename Name
Renames the file to the target file specified by Name.
| Parameter |
Description |
| Name |
String
containing the Target path for the Rename
operation. |
Returns: Nothing
Notes: The Rename method allows you to rename or move the file currently
being referenced by the File object. Afterwards, the File object references the file in
the new location.
Example: The following example shows how to rename file
"old.zip" to "new.zip":
Set File = Server.CreateObject("ActiveFile.File")
File.Name = "C:\old"
File.Rename "C:\new"
See Also: File.Name property
|