ASP TextStream Object
The TextStream Object
The TextStream object is used to access the contents of text files.
The following code creates a text file (c:\test.txt) and then writes some text to the file (the variable f is an instance of the TextStream object):
<%
dim fs, f
set fs=Server.CreateObject("Scripting.FileSystemObject")
set f=fs.CreateTextFile("c:\test.txt",true)
f.WriteLine("Hello World!")
f.Close
set f=nothing
set fs=nothing
%>
|
To create an instance of the TextStream object you can use the CreateTextFile or OpenTextFile methods of the FileSystemObject object, or you can use the OpenAsTextStream method of the File object.
The TextStream object’s properties and methods are described below:
Properties
| Property | Description |
|---|---|
| AtEndOfLine | Returns true if the file pointer is positioned immediately before the end-of-line marker in a TextStream file, and false if not |
| AtEndOfStream | Returns true if the file pointer is at the end of a TextStream file, and false if not |
| Column | Returns the column number of the current character position in an input stream |
| Line | Returns the current line number in a TextStream file |
Methods
| Method | Description |
|---|---|
| Close | Closes an open TextStream file |
| Read | Reads a specified number of characters from a TextStream file and returns the result |
| ReadAll | Reads an entire TextStream file and returns the result |
| ReadLine | Reads one line from a TextStream file and returns the result |
| Skip | Skips a specified number of characters when reading a TextStream file |
| SkipLine | Skips the next line when reading a TextStream file |
| Write | Writes a specified text to a TextStream file |
| WriteLine | Writes a specified text and a new-line character to a TextStream file |
| WriteBlankLines | Writes a specified number of new-line character to a TextStream file |
File System Object
The FileSystemObject Object
The FileSystemObject object is used to access the file system on the server. This object can manipulate files, folders, and directory paths. It is also possible to retrieve file system information with this object.
The following code creates a text file (c:\test.txt) and then writes some text to the file:
| <% dim fs,fname set fs=Server.CreateObject(“Scripting.FileSystemObject”) set fname=fs.CreateTextFile(“c:\test.txt”,true) fname.WriteLine(“Hello World!”) fname.Close set fname=nothing set fs=nothing %> |
The FileSystemObject object’s properties and methods are described below:
Properties
| Property | Description |
|---|---|
| Drives | Returns a collection of all Drive objects on the computer |
Methods
| Method | Description |
|---|---|
| BuildPath | Appends a name to an existing path |
| CopyFile | Copies one or more files from one location to another |
| CopyFolder | Copies one or more folders from one location to another |
| CreateFolder | Creates a new folder |
| CreateTextFile | Creates a text file and returns a TextStream object that can be used to read from, or write to the file |
| DeleteFile | Deletes one or more specified files |
| DeleteFolder | Deletes one or more specified folders |
| DriveExists | Checks if a specified drive exists |
| FileExists | Checks if a specified file exists |
| FolderExists | Checks if a specified folder exists |
| GetAbsolutePathName | Returns the complete path from the root of the drive for the specified path |
| GetBaseName | Returns the base name of a specified file or folder |
| GetDrive | Returns a Drive object corresponding to the drive in a specified path |
| GetDriveName | Returns the drive name of a specified path |
| GetExtensionName | Returns the file extension name for the last component in a specified path |
| GetFile | Returns a File object for a specified path |
| GetFileName | Returns the file name or folder name for the last component in a specified path |
| GetFolder | Returns a Folder object for a specified path |
| GetParentFolderName | Returns the name of the parent folder of the last component in a specified path |
| GetSpecialFolder | Returns the path to some of Windows’ special folders |
| GetTempName | Returns a randomly generated temporary file or folder |
| MoveFile | Moves one or more files from one location to another |
| MoveFolder | Moves one or more folders from one location to another |
| OpenTextFile | Opens a file and returns a TextStream object that can be used to access the file |
ASP Error object
The ASPError object is used to display detailed information of any error that occurs in scripts in an ASP page.
The ASPError Object
The ASPError object was implemented in ASP 3.0 and is available in IIS5 and later.
The ASPError object is used to display detailed information of any error that occurs in scripts in an ASP page. The ASPError object is created when Server.GetLastError is called, so the error information can only be accessed by using the Server.GetLastError method.
The ASPError object’s properties are described below (all properties are read-only):
Note: The properties below can only be accessed through the Server.GetLastError() method.
Properties
| Property | Description |
|---|---|
| ASPCode | Returns an error code generated by IIS |
| ASPDescription | Returns a detailed description of the error (if the error is ASP-related) |
| Category | Returns the source of the error (was the error generated by ASP? By a scripting language? By an object?) |
| Column | Returns the column position within the file that generated the error |
| Description | Returns a short description of the error |
| File | Returns the name of the ASP file that generated the error |
| Line | Returns the line number where the error was detected |
| Number | Returns the standard COM error code for the error |
| Source | Returns the actual source code of the line where the error occurred |
ASP Application Object
A group of ASP files that work together to perform some purpose is called an application. The Application object in ASP is used to tie these files together.
Application Object
An application on the Web may be a group of ASP files. The ASP files work together to perform some purpose. The Application object in ASP is used to tie these files together.
The Application object is used to store and access variables from any page, just like the Session object. The difference is that ALL users share one Application object, while with Sessions there is one Session object for EACH user.
The Application object should hold information that will be used by many pages in the application (like database connection information). This means that you can access the information from any page. It also means that you can change the information in one place and the changes will automatically be reflected on all pages.
The Application object’s collections, methods, and events are described below:
Collections
| Collection | Description |
|---|---|
| Contents | Contains all the items appended to the application through a script command |
| StaticObjects | Contains all the objects appended to the application with the HTML <object> tag |
Methods
| Method | Description |
|---|---|
| Contents.Remove | Deletes an item from the Contents collection |
| Contents.RemoveAll() | Deletes all items from the Contents collection |
| Lock | Prevents other users from modifying the variables in the Application object |
| Unlock | Enables other users to modify the variables in the Application object (after it has been locked using the Lock method) |
Events
| Event | Description |
|---|---|
| Application_OnEnd | Occurs when all user sessions are over, and the application ends |
| Application_OnStart | Occurs before the first new session is created (when the Application object is first referenced) |



