Use ADODB.stream instead of FSO to read text files

Source: Internet
Author: User
Ado|fso|stream yesterday I asked this question, but no one answered the point, and today it's done. Posted out to feel useful friends, hope that other friends do not have to detour.

' Read the contents of the file.
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
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



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.