VBScript » File » OpenAsTextStream

Version: 3.0

Syntax:
object.OpenAsTextStream([iomode [,format]])
iomode
Used to set the mode input/output mode of the newly opened file. You must specify one of the values contained in the iomode Values table.
format
Specifies the format that will be used to open the file. You must specify one of the values contained in the format Values table.

This method opens a specified file and returns an instance of a TextStream object that can then be manipulated - read from, written or appended to.

iomode Values

Constant Value Description
ForReading
1
File is opened for reading only
ForWriting
2
File is opened for writing and the contents of any existing file with the same name are overwritten
ForAppending
8
Opens the file and writes to the end of any existing text.


format Values

Constant Value Description
TristateUseDefault
-2
Uses the system default file format
TristateTrue
-1
Opens the file using the Unicode format
TristateFalse
0
Opens the file in AscII format

Examples

Code:
<%
dim filesys, demofile, txtstream
set filesys = CreateObject ("Scripting.FileSystemObject")
set demofile = filesys.CreateTextFile ("c:\somefile.txt", true)
set demofile = filesys.GetFile("c:\somefile.txt")
set txtstream = demofile.OpenAsTextStream (2, -2)
txtstream.Write "This will overwrite any text already in the file."
txtstream.Close
%>