|
|
|
Data-access,
Using ASCII text-files with FileSystemObject
ASP can create new objects, with methods and properties.
One of these objects is Scripting.FilesystemObject
The following code let you write to a existing file.
Set fs = CreateObject("Scripting.FileSystemObject")
froot = server.MapPath("\MyPath")
Set f = fs.GetFile(froot&"\MyFile.txt")
Set ts = f.OpenAsTextStream(2,0)
ts.Write "text to write"
ts.Close
Set ts = f.OpenAsTextStream(inputOutPutMode,textFileFormat)
inputOutPutMode can be: 1 - for reading, 2 - for writing, 8 - for appending.
textFileFormat can be one of 3 values: -2 - uses default system type, -1 - creates the textfile in unicode format, 0 - creates the textfile in ascii format.
If you enter the following line you can also create a file.
fs.CreateTextFile froot&"\MyFile.txt"
Example code for reading a file:
Set fs = CreateObject("Scripting.FileSystemObject")
froot = server.MapPath("\MyPath")
Set f = fs.GetFile(froot&"\MyFile.txt")
Set ts = f.OpenAsTextStream(1,0)
s = ts.ReadLine
Response.Write(s)
If you want write ine several line use WriteLine.
TOP
|
|