Skip to content
Related Articles
Get the best out of our app
Open App

Related Articles

ASP OpenTextFile Method

Improve Article
Save Article
Like Article
Improve Article
Save Article
Like Article

The ASP OpenTextFile Method is used to open a specified file. It returns a TextStream object that can be used to read, write and append contents to the File. It is an in-built function of the FileSystem Object. 



Parameter Value:

  • fname: Required attribute. It specifies the name of the file to be opened.
  • mode: It is an optional attribute. It specifies that how to open a file. It contains 3 constant values to perform an operation on a file.  
    • 1 for reading the contents.
    • 2 open a file for writing the contents
    • 8 for appending the contents.
  • create: Optional Attribute. It contains a Boolean value that specifies that whether there can be created if the specified filename doesn’t exist.  
    • The value is True if a new file is created;
    • false if it isn’t created. The default is False.
  • Format: Optional attribute. It contains three constant value which used to define a format of a file 
    • 0=TristateFalse – Open the file as ASCII. This is the default.
    • -1=TristateTrue – Open the file as Unicode.
    • -2 =TristateUseDefault – Open the file using the system default.

Example Code:  Below code illustrates that how to open a new file for writing the content


dim fs,f
set fs=Server.CreateObject("Scripting.FileSystemObject")
set f=fs.OpenTextFile(Server.MapPath("GFG.txt"),2,true)
response.write("File is open for purpose of writing")
f.WriteLine("This text will be added to the end of file")
set f=Nothing
set fs=Nothing





File is open for purpose of writing


My Personal Notes arrow_drop_up
Last Updated : 03 Feb, 2022
Like Article
Save Article
Similar Reads
Related Tutorials