ASP to use ADODB.stream instead of FSO to read text files _ Thieves/collection

Source: Internet
Author: User
' 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")
%>
Related Article

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.