昨天我問過這個問題,不過沒人回答到點上,今天搞定了.貼出來給覺得有用的朋友,希望其他朋友不用走彎路.
'文件內容讀取.
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'>非常遺憾,您的主機不支持ADODB.Stream,不能使用本程序</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'>文件<font color='#ff0000'>"&File&"</font>無法被打開,請檢查是否存在!</font></div>"
Err.Clear
Response.End
End If
.Charset = "GB2312"
.Position = 2
LoadFile = .ReadText
.Close
End With
Set obJStream = Nothing
End Function
'存儲內容到文件
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'>非常遺憾,您的主機不支持ADODB.Stream,不能使用本程序</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