<%
Dim s
s = "show license 1"
s = s & vbCrLf & "show 1 license"
SaveEncodedTextFile("C:\aFile.txt", "utf-8", s)
%>
以上 SaveEncodedTextFile() 子過程(函數)就是專門用來保存文本文件的,其源代碼如下(也可以上 /blog/post/SaveTextFile.html 查看):
<%
' 保存文本文件
Function SaveEncodedTextFile(sFilePath, sCharset, s)
Dim oStream
Set oStream = Server.CreateObject("ADODB.Stream")
' 以文本模式
oStream.Type = 2
oStream.Mode = 3
If Len(sCharset) > 0 Then
On Error Resume Next
oStream.Charset = sCharset
If Err.number <> 0 Then
oStream.Charset = "_autodetect_all"
End If
On Error Goto 0
End If
oStream.Open
oStream.WriteText s
' 2 - adSaveCreateOverwrite
On Error Resume Next
oStream.SaveToFile sFilePath, 2
If Err.number <> 0 Then
SaveEncodedTextFile = False
Else
SaveEncodedTextFile = True
End If
On Error Goto 0
Set oStream = Nothing
End Function
%>