Open In App

ASP CreateTextFile Method

Last Updated : 03 Mar, 2021
Improve
Improve
Like Article
Like
Save
Share
Report

The ASP CreateTextFile Method is used to create a new Text file in the current Directory It returns a TextStream Object which can be used to read and write the contents to a File. 

Syntax:

FileSystemObject.CreateTextFile(filename[,overwrite[,unicode]])

Parameter Values:

  • filename: It specifies the name of the newly created File.
  • overwrite: It is an optional attribute. It contains a Boolean value which indicates that whether an existing file can be overwritten. True indicates that the file can be overwritten and False indicates that the file can not be overwritten. Default is True.
  • unicode: It is an optional attribute. It contains a Boolean value that indicates whether the file is created as a Unicode or an ASCII file. True indicates that the file is created as a Unicode file, False indicates that the file is created as an ASCII file. Default is False.

Example: Below code demonstrates the ASP CreateTextFile Method. 

ASP




<%
dim fs,tfile
set fs=Server.CreateObject("Scripting.FileSystemObject")
set tfile=fs.CreateTextFile("e:\GeeksGFG.txt"
tfile.WriteLine("Hello GeeksForGeeks!")
tfile.close
Response.write("File is closed")
set tfile=nothing
set fs=nothing
%>


Output:

File is closed

Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads