ASP CreateTextFile method

Definition and Usage

The CreateTextFile method can create a new text file in the current folder and return a TextStream object that can be used to read or write to the file.

Syntax:

FileSystemObject.CreateTextFile(filename[,overwrite[,unicode]])
FolderObject.CreateTextFile(filename[,overwrite[,unicode]])
Parameter Description
filename Required. The name of the file to be created.
overwrite Optional. Boolean value indicating whether it is possible to overwrite the existing file. True indicates that it is possible to overwrite the file, while False indicates that it is not possible to overwrite the file. The default is True.
unicode Optional. Boolean value indicating whether the file is created as Unicode or ASCII. True indicates that the file is created as a Unicode file, while False indicates that the file is created as an ASCII file. The default is False.

instance for FileSystemObject

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

instance for Folder object

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