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]])
Parameters | 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 the file can be overwritten, while False indicates that the file cannot be overwritten. The default is True. |
unicode | Optional. Boolean value indicating whether the file is created as Unicode or ASCII. True indicates the file is created as a Unicode file, while False indicates the file is created as an ASCII file. The default is False. |
instance of 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 of 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 %>