For those that do not use FSO under ASP, use the adodb.stream object to save and read files to avoid machines that have some virtual hosts that do not support FSO. '************************************
'Read the file
'************************************
Function LoadFromFile(ByVal File)
Dim objStream
Dim RText
RText = Array(0, )
Set objStream = Server.CreateObject(ADODB.Stream)
With objStream
.Type = 2
.Mode = 3
.Open
.Charset = utf-8
.Position = objStream.Size
On Error Resume Next
.LoadFromFile Server.MapPath(File)
If Err Then
RText = Array(Err.Number, Err.Description)
LoadFromFile = RText
Err.Clear
Exit Function
End If
RText = Array(0, .ReadText)
.Close
End With
LoadFromFile = RText
Set objStream = Nothing
End Function
'************************************
'Save file
'************************************
Function SaveToFile(ByVal strBody, ByVal File)
Dim objStream
Dim RText
RText = Array(0, )
Set objStream = Server.CreateObject(ADODB.Stream)
With objStream
.Type = 2
.Open
.Charset = utf-8
.Position = objStream.Size
.WriteText = strBody
On Error Resume Next
.SaveToFile Server.MapPath(File), 2
If Err Then
RText = Array(Err.Number, Err.Description)
SaveToFile = RText
Err.Clear
Exit Function
End If
.Close
End With
RText = Array(0, file saved successfully!)
SaveToFile = RText
Set objStream = Nothing
End Function