Name
Write (TextStream Object) —
tsObj
.Write(
strWriteString
)
Synopsis
Writes a specified string to an open text file at the current location of the file pointer.
Parameters
-
strWriteString
A string that represents the text you wish to write to the open file
Example
<%
' Dimension local variables.
Dim fsoObject ' FileSystemObject
Dim filObject ' File Object
Dim tsObject ' TextStream object
Dim strEnding
' Declare file access constants.
Const ForAppending = 8
Const TristateFalse = 0
' Initialize string variable. This string will be
' written to the end of the file opened next.
strEnding = "This is the end, my only friend, the end..."
' Instantiate the FileSystemObject variable.
Set fsoObject = Server.CreateObject( _
"Scripting.FileSystemObject")
' Using the GetFile method of fsoObject, initialize the
' File object.
Set filObject = fsoObject.GetFile("d:\docs\test.txt")
' Use the OpenAsTextStream method to open the file for
' appending and in Unicode format.
Set tsObject = filObject.OpenAsTextStream(ForAppending, TristateFalse)
' Write a short string to the end of the opened file.
tsObject.Write strEnding
. . . [additional code]
%>
Notes
The Write method does not place any characters at the beginning or end of each written string. For this reason, if you use the Write method to add to a file, make sure that you include any desired characters (like spaces or newline characters) at the beginning or end of the strings you write to the file.
Get ASP in a Nutshell, 2nd Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.