The ASP CreateTextFile Method is used to create a new text file in the current folder or directory. It returns a TextStream object that can be used to perform operations on the file.
For Folder Object:
FolderObject.CreateTextFile(filename, overwrite, unicode)
For FileSystem Object:
FileSystemObject.CreateTextFile(filename, overwrite, unicode)
Parameters: This property has three parameters as mentioned above and described below:
- filename: It specifies the name of the text file to be newly created.
- overwrite: It contains a boolean value that indicates whether an existing file can be overwritten. The true value indicates that the file can be overwritten and false indicates that no overwriting is allowed. The default value is true. It is an optional parameter.
- unicode: It contains a boolean value that indicates whether the file is created as a Unicode or ASCII file. The true value indicates that the file is created as a Unicode file and a false value indicates that it is created as an ASCII file. The default value is false. It is an optional parameter.
The below examples demonstrate the ASP CreateTextFile Method.
Example 1: The below example demonstrates the ASP Folder.CreateTextFile Method.
A new textfile has been created! The File Contents are: Hello Geeks!
Example 2: The below example demonstrates the ASP FileSystemObject.CreateTextFile Method.
The new text file has been created! The File Contents are: Hello World!