What is the FileSystemObject and ASPError Object of ASP
I have very recently started studying ASP(Active Server Pages). I have to work on a website which is built on ASP. This is the first time I am going to work on a website. I had earlier studied HTML(Hyper Text Markup Language) and Java, which is somewhat a bit helpful for me to understand very few concepts in ASP. But I am not able to understand the FileSystemObject and ASPError Object.
ASP Object: FileSystemObject
To access the file system which resides on a server the FileSystemObject object is used. To act upon the folder, directories paths and files the FileSystemObject is useful. Using this ASP Object we can gather file system information. Even I was confused when I started to learn the FileSystemObject in ASP.
Creating an ASP text file
Here is an example of how to create a Text file in Active Server Pages and then write some text to it. The file is stored at D:\temp.txt:
Code:
<%
dim files,filen
set files=Server.CreateObject("Scripting.FileSystemObject")
set filen=files.CreateTextFile("D:\temp.txt",true)
filen.WriteLine("New Entry")
filen.Close
set filen=nothing
set files=nothing
%>
The above code writes text 'New Entry' to the temp.txt file.
Properties of ASPError Object
Following are the properties of the ASPError object:
- Description: To get a short description of the error we use the Description property of the ASPError object.
- ASPDescription: To get the detailed information of the occurred error we use the ASPDescription property of the ASPError object.
- Number: To get the standard COM error of the error occurred we use the Number property of the ASPError object.
- File: To get the name for the ASP file which actually generated the error we use the File property of the ASPError object.
- ASPCode: The IIS generates an error code for an error, to get this error code we use the ASPCode property of the ASPError object.
FileSystem object methods
Here are a few methods of the ASP FileSystem object:
- The BuildPath method: To add name to an already existing path, BuildPath method is used. The syntax for this is:
Quote:
[newpath=]FileSystemObject.BuildPath(path,name)
In the above syntax the parameter name means the name which is to be added to the path and the parameter oath means the path to append a name to. - The CopyFile Method: To copy a file in ASP, the CopyFile method is used. The syntax is:
Quote:
FileSystemObject.CopyFile source,destination[,overwrite]
In the above syntax, the parameter destination denotes the location where the file is to be copied, the parameter source denotes the file to be copied and the parameter overwrite is optional and denotes whether the existing file can be overwritten or not.