' Read the contents of the file.
Copy Code code as follows:
Function loadfile (ByVal File)
Dim objstream
On Error Resume Next
Set objstream = Server.CreateObject ("ADODB. Stream ")
If err.number=-2147221005 Then
Response.Write "<div align= ' center ' > Very sorry, your host does not support ADODB.stream, can not use this program </div>"
Err.Clear
Response.End
End If
With Objstream
. Type = 2
. Mode = 3
. Open
. LoadFromFile Server.MapPath (File)
If err.number<>0 Then
Response.Write "<div align= ' center ' > File <font color= ' #ff0000 ' > ' &File& ' </font> cannot be opened, Please check if there is a!</font></div> "
Err.Clear
Response.End
End If
. Charset = "GB2312"
. Position = 2
LoadFile =. ReadText
. Close
End With
Set objstream = Nothing
End Function
' Store content to file
Copy Code code as follows:
Sub SaveToFile (ByVal strbody,byval File)
Dim objstream
On Error Resume Next
Set objstream = Server.CreateObject ("ADODB. Stream ")
If err.number=-2147221005 Then
Response.Write "<div align= ' center ' > Very sorry, your host does not support ADODB.stream, can not use this program </div>"
Err.Clear
Response.End
End If
With Objstream
. Type = 2
. Open
. Charset = "GB2312"
. Position = Objstream.size
. WRITETEXT = Strbody
. SaveToFile Server.MapPath (File), 2
. Close
End With
Set objstream = Nothing
End Sub
Call Example
Copy Code code as follows:
<%
WriteFile "Aaa.txt", "www.jb51.net", "Utf-8"
Response.Write ReadFile ("Aaa.txt", "Utf-8")
%>