วิธี CreateTextFile ของ ASP

การระบุและวิธีใช้

วิธีใช้ CreateTextFile หลักฐานสามารถสร้างไฟล์เอกสารใหม่ในไดเรกทอรีปัจจุบันและกลับคืนตัวแปร TextStream ที่สามารถใช้เพื่ออ่านหรือเขียนไฟล์

คำนำออก

FileSystemObject.CreateTextFile(filename[,overwrite[,unicode]])
FolderObject.CreateTextFile(filename[,overwrite[,unicode]])
ตัวแปร คำอธิบาย
filename จำเป็น。ต้องมีชื่อไฟล์ที่ต้องการสร้าง
overwrite ตัวเลือก。กำหนดว่าสามารถทำร้ายไฟล์ที่มีอยู่หรือไม่ โดยค่าบูลเลียน True หมายถึงการทำร้ายไฟล์ที่มีอยู่ และ False หมายถึงไม่สามารถทำร้ายไฟล์ที่มีอยู่ โดยมีค่าโดยเริ่มต้นเป็น True。
unicode ตัวเลือก。กำหนดว่าไฟล์จะถูกสร้างในรูปแบบ Unicode หรือ ASCII โดยค่าบูลเลียน True หมายถึงการสร้างไฟล์ในรูปแบบ Unicode และ False หมายถึงการสร้างไฟล์ในรูปแบบ ASCII โดยมีค่าโดยเริ่มต้นเป็น False。

สำหรับตัวแปร 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
%>

สำหรับตัวแปร Folder ตัวเดียว

<%
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
%>