ASP OpenTextFile Method

Definition and Usage

The OpenTextFile method opens the specified file and returns a TextStream object that can be used to access this file.

Syntax:

FileSystemObject.OpenTextFile(fname,mode,create,format)
Parameter Description
fname Required. The name of the file to be opened.
mode Optional. How to open the file.
  • 1=ForReading - Open the file for reading data. You cannot write data to this file.
  • 2=ForWriting - Open the file for writing data.
  • 8=ForAppending - Open the file and write data to the end of the file.
create Optional. Set whether to create a new file if the file name does not exist. True indicates that a new file can be created, while False indicates that a new file will not be created. False is the default.
format Optional. File format.
  • 0=TristateFalse - Open files in ASCII. Default.
  • -1=TristateTrue - Open files in Unicode.
  • -2=TristateUseDefault - Open files using the system default format.

Instance

<%
dim fs,f
set fs=Server.CreateObject("Scripting.FileSystemObject")
set f=fs.OpenTextFile(Server.MapPath("testread.txt"),8,true)
f.WriteLine("This text will be added to the end of file")
f.Close
set f=Nothing
set fs=Nothing
%>