Thứ Hai, 24 tháng 10, 2011

ASP: Write file utf8


Sub LogEvent(message, filename)
sDate = Now()

'filename
if filename <> "" then
filename = filename & "_" & year(sDate)&month(sDate)&day(sDate)
else
filename = year(sDate)&month(sDate)&day(sDate)
end if
filename = server.mappath(".") & "/log/" & filename

'check file exists
Set fs = CreateObject("Scripting.FileSystemObject")
If fs.FileExists(filename) Then
modeFile = 2
else
modeFile = 1
end if
set fs = nothing

'write file
Set objStream = server.CreateObject("ADODB.Stream")
objStream.Open
objStream.CharSet = "UTF-8"

if modeFile = 2 then
objStream.LoadFromFile filename
objStream.ReadText
end if

objStream.WriteText(sDate & vbTab & message & vbNewLine)

objStream.SaveToFile filename , modeFile
objStream.Close
set objStream = nothing
End Sub


(http://gchandra.wordpress.com/2004/08/19/creating-utf-8-files-using-asp/, http://www.w3schools.com/ado/ado_ref_stream.asp)

Không có nhận xét nào:

Đăng nhận xét