
December 5th, 2003, 09:11 PM
|
 |
Newton's Apple Wizard
|
|
Join Date: Nov 2003
Location: Los Angeles
|
|
This is how you write to a file in ASP...
This is the code for APPENDING to a text file. This means what is already in the file will NOT be overwritten.
Code:
<%
Dim Stuff, myFSO, WriteStuff
'this is what we will write in the file
Stuff = "Here is some stuff to write in the file."
'this line creates an instance of the File Scripting Object named myFSO
Set myFSO = CreateObject("Scripting.FileSystemObject")
'this line opens the file, notice the 8, it will cause the script to append to the file
Set WriteStuff = myFSO.OpenTextFile("C:\Inetpub\wwwroot\myNewFolder\myNewText.txt", 8, True)
'this line actually writes STUFF from above to the file
WriteStuff.WriteLine(Stuff)
''this line closes the file
WriteStuff.Close
'this line destroys the instance of the File Scripting Object named WriteStuff
SET WriteStuff = NOTHING
'this line destroys the instance of the File Scripting Object named myFSO
SET myFSO = NOTHING
%>
This is the code for WRITING to a file. It will do just the opposite of the above. It will OVERWRITE anything already in the file.
Code:
<%
Dim Stuff, myFSO, WriteStuff
'this is what we will write in the file
Stuff = "Here is some stuff to write in the file."
'this line creates an instance of the File Scripting Object named myFSO
Set myFSO = CreateObject("Scripting.FileSystemObject")
'this line opens the file, notice the 1, it will cause the script to write to the file (overwriting existing text)
Set WriteStuff = myFSO.OpenTextFile("C:\Inetpub\wwwroot\myNewFolder\myNewText.txt", 8, True)
'this line actually writes STUFF from above to the file
WriteStuff.WriteLine(Stuff)
''this line closes the file
WriteStuff.Close
'this line destroys the instance of the File Scripting Object named WriteStuff
SET WriteStuff = NOTHING
'this line destroys the instance of the File Scripting Object named myFSO
SET myFSO = NOTHING
%>
|