ASP CreateTextFile Method

Definition and Usage

The CreateTextFile method creates a new text file in the current folder and returns a TextStream object for reading and writing this file.

Syntax:

FileSystemObject.CreateTextFile(filename[,overwrite[,unicode]])
FolderObject.CreateTextFile(filename[,overwrite[,unicode]])
Parameters Description
filename Required. The name of the file to be created.
overwrite Optional. Indicates whether to overwrite an existing file as a boolean value. True means to overwrite this file, while False means not to overwrite this file. The default is True.
unicode Optional. Indicates whether to create the file in Unicode or ASCII format. True indicates to create the file in Unicode format, False indicates to create the file in ASCII format. The default is False.

Instance

Example for File object

<%
dim fs,tfile
set fs=Server.CreateObject("Scripting.FileSystemObject")
set tfile=fs.CreateTextFile("d:\somefile.txt")
tfile.WriteLine("Hello World!")
tfile.close
set tfile=nothing
set fs=nothing
%>

Example for Folder object

<%
dim fs,fo,tfile
Set fs=Server.CreateObject("Scripting.FileSystemObject") 
Set fo=fs.GetFolder("d:\test") 
Set tfile=fo.CreateTextFile("somefile.txt",false)
tfile.WriteLine("Hello World!")
tfile.Close
set tfile=nothing
set fo=nothing
set fs=nothing
%>