Building WebApps  «Prev  Next»

Lesson 6The FileSystemObject
ObjectiveDescribe the FileSystemObject

ASP FileSystemObject Description

Why read and write files using ASP?

Although the use of "flat" text files might seem outmoded, the ability to read and write to files is still often effective for transferring data.
Historically, reading and writing text files has been a way to pass information, especially large amounts of information, among programs. With ASP, you can use Session objects (and Application objects, discussed later) to transfer data between ASP scripts. If you need to store information beyond the length of a user Session or the time an application runs, you can use ASP's database access tools (discussed later) to read and write database records.
But sometimes you need a file. For example, you might build a file for site visitors to use at a later point in their sessions, perhaps a listing of items they browsed while shopping. Or, you may want to let users send information to friends or coworkers, so you create a file and attach it to an email.

The FileSystemObject

Summary of the File System Object

Summary of the FileSystemObje
Objects:
Drive Contains methods and properties that allow you to gather information about a drive attached to the system, such as its share name and how much room is available.
File Contains methods and properties that allow you to create, delete, or move a file. Also allows you to query the system for a file name, path, and various other properties.
Folder Contains methods and properties that allow you to create, delete, or move folders. Also allows you to query the system for folder names, paths, and various other properties.
TextStream Allows you to read and write text files.
Collections:
Drives Provides a list of all the drives, regardless of type, attached to the system, either physically or logically. Removable-media drives need not have media inserted for them to appear in this collection.
Files Provides a list of all files contained within a folder.
Folders Provides a list of all the folders within a Folder.

What is the purpose of the FileSystemObject in Classis ASP

The FileSystemObject (FSO) is a component of Microsoft's scripting engine that provides access to the file system on a server running Microsoft Windows. In Classic ASP, the FileSystemObject can be used to perform various file and folder operations, such as reading, writing, and deleting files, as well as creating, deleting, and manipulating directories. The FileSystemObject provides a way for ASP scripts to interact with the file system on the server, enabling developers to build dynamic and interactive web applications that can manipulate files and folders on the server.
The FileSystemObject also represents all the drives (including network-shared drives), directories, and files on a machine: it puts the entire file system in your hands. Creating and using the FileSystemObject is a little different from employing ASP components, because we're using an object from the scripting language (VBScript or JScript).
Even though this is a scripting object and not an ASP object, scripting objects have methods and properties that are used similarly to those in ASP. Previously, scripting languages were restricted from creating, reading, and writing files for security reasons. The next lesson describes how to use the FileSystemObject to create and write to a text file.