Building WebApps  «Prev  Next»

Lesson 6The FileSystemObject
ObjectiveDescribe the FileSystemObject

Why read and write files?

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

You can create, write, and read text files with the FileSystem Object
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.