|
|
| MAKE/WRITE/DELETE TEXTFILES IN ASP |
|
When you want to store some data, either how many viewers your page have registered,
or you want to make a simple guestbook, you have to store the data. Textfiles is
a rather easy way to do this. In this tutorial I will show how to make, write to and
delete a textfile. I will not make a live example in this tutorial due to security. But you can
cut and paste the code into your own code.
|
Make And Write To A File
|
|
You use the same methods for writing to a file, and making a new. If the file
already exists, you will repleace the content with the new -> write new data to it.
|
Dim filename, fs, f
filename = "myfirstfile.txt"
Set fs=Server.CreateObject("Scripting.FileSystemObject")
Set f=fs.CreateTextFile(filename,true)
f.write("Apron! This is my first file")
f.close
Set f=nothing
Set fs=nothing
|
|
The file above will have this output:
|
Apron! This is my first file.
|
|
|
If you want to replace part of the text file, I recommend you use xml files
or a database to store your data. I have however made a wrapper class where
you can manipulate the textfile. You can download the class and read more about it
here.
|
Dim filename, fs, f
filename = "myfirstfile.txt"
Set fs=Server.CreateObject("Scripting.FileSystemObject")
Set f=fs.GetFile(Server.MapPath(filename))
f.Delete
Set f=nothing
Set fs=nothing
|
|
Category
|
Programming with ASP
|
|
Author
|
Tommy Johannessen
|
|
|
|