The FileSystemObject, or FSO, is an often used component to access the web server's file system. For example, you can create files, read the contents of files, determine whether or not a folder or file exists, iterate through the contents of a folder or directory, or any other number of file system-related tasks. You can create an instance of the FileSystemObject component in an ASP page with the following code:
Once you create an instance of this component, you can access its many properties and methods. For example,
say that you wanted to output the contents of the text file
C:\SomeFile.txt. The following code could
We'll look at reading text files in more detail in the next FAQ. For now, just understand that the FileSystemObject's purpose is to allow an ASP page (or VB program, or WSH file) to have access to the machine's file system. Since your ASP pages reside and are executed on the web server, when using FSO to access the file system, you are accessing the web server's file system. You cannot access the client's file system using the FileSystemObject in your ASP code.
One important thing to keep in mind when using the
FileSystemObject is permissions! In Windows NT, there are three types of permissions: Read, Write, and Full Access. Whenever an ASP page
attempts to execute some file system command using FSO, the anonymous web user ID is used:
IUSR_machinename (i.e., if your webserver is named
Bob, the user ID is
IUSR_machinename doesn't have permissions to Read for
a particular directory, you cannot use FSO to read the contents of a file in that directory through an ASP page. If
IUSR_machinename doesn't have permissions to Write for
a particular directory, you cannot use FSO to write a file to that directory through an ASP page. If
IUSR_machinename doesn't have Full Access permissions for
a particular directory, you cannot use FSO to delete or move a file from that directory through an ASP page.