Use ADODB. Stream in ASP to replace FSO to read text files

Source: Internet
Author: User

'File content reading. CopyCode The Code is 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'> sorry, your host does not support ADODB. Stream and cannot 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. Check whether the file exists! </Font> </div>"
Err. Clear
Response. End
End if
. Charset = "gb2312"
. Position = 2
LoadFile =. readtext
. Close
End
Set objstream = nothing
End Function

'Store content to a fileCopy codeThe Code is 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'> sorry, your host does not support ADODB. Stream and cannot 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
Set objstream = nothing
End sub

Call exampleCopy codeThe Code is 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.