eHow launches Android app: Get the best of eHow on the go.

How To

How to Write Data to a File with Classic ASP

Member
By onionsaredabest
User-Submitted Article
(1 Ratings)

Writing data to a file in Classic ASP is simple, and can be an invaluable tool for logging and troubleshooting web applications. VBScript provides all of the methods needed to write to files, and the task can be accomplished in just a few lines of code!

Difficulty: Easy
Instructions

Things You'll Need:

  • Windows machine running IIS / Classic ASP
  1. Step 1

    Create a FileSystemObject object. The FileSystemObject object is used to access files and folders, which is the basis for writing data to a file. The object can be created like so:

    Set fso = CreateObject("Scripting.FileSystemObject")

  2. Step 2

    Decide whether the data to be written will overwrite or add on (append) to existing data. When writing event data to a single log file for example, the data should be appended to whatever is currently in the log file. Otherwise, the log will only contain a record of the last event. Once the decision has been made, decide which file to write data into.

  3. Step 3

    Open the file. In classic ASP, a file must be opened before it can be written to. A file can be opened for overwriting like so:

    Set logFile = fso.OpenTextFile("C:\MyFile.txt, 2)

    The "2" means to overwrite any data already in the "C:\MyFile.txt" file. Opening a file for appending is accomplished using an "8" instead:

    Set logFile = fso.OpenTextFile("C:\MyFile.txt, 8)

  4. Step 4

    Write to the file. Once the file has been opened, it can then be written to:

    logFile.WriteLine("Writing data to a file in Classic ASP is easy!")

  5. Step 5

    Close the file. It is a good practice to always close a file after it has been opened, and then free up memory that was assigned to any objects created during the process:

    logFile.Close
    Set logFile = nothing
    Set fso = nothing

  6. Step 6

    Here is the data-writing code in its entirety:

    Set fso = CreateObject("Scripting.FileSystemObject")
    Set logFile = fso.OpenTextFile("C:\MyFile.txt, 8)
    logFile.WriteLine("Writing data to a file in classic ASP is easy!")
    logFile.Close
    Set logFile = nothing
    Set fso = nothing

    Six lines of code is all it takes to write to a file in Classic ASP!

Tips & Warnings
  • Ensure that proper permissions are setup on the server to allow for creating and writing files using Classic ASP
Subscribe

Post a Comment

Post a Comment

Related Ads

  • Have you done this? Click here to let us know.
I Did This
Get Free Computers Newsletters

Copyright © 1999-2009 eHow, Inc. Use of this web site constitutes acceptance of the eHow Terms of Use and Privacy Policy.   en-US Portions of this page are modifications based on work created and shared by Google and used according to terms described in the Creative Commons 3.0 Attribution License.

eHow Computers
eHow_eHow Technology and Electronics