ASP: File Operation Class Based on ADODB. Stream

Source: Internet
Author: User
<%

'*************************************** **********************
'Keep this declaration information during forwarding. This declaration does not affect your speed!
'*************************************** **********************

'*************************************** **********************
'@ Author: Noodle
'@ Realname: Xu renlu
'@ Email: xurenlu@sohu.com
'@ Qq: 55547082'
'@ Homepage: http://www.ksdn.net
'@ Copyright:
'Non-profit groups or individuals can use them for free.
'*************************************** **********************

'*************************************** **********************
'Class name: Files
'Class function: implements file read/write, and uses ADODB. Stream to read and write files on hosts that do not support FSO.
'*************************************** **********************

Class files


Private adsavecreateoverwrite 'existing files can be overwritten during file creation.
Private adsavecreatenotexist: if the file does not exist when saving the file, you can create a file.

'*************************************** **********************
'Event name: class_initialize ()
'Event Occurrence Condition: this event is generated when the class is created.
'Event content: assign values to private variables
'Event input parameters: None
'*************************************** **********************

Sub class_initialize ()
Adsavecreateoverwrite = 2
Adsavecreatenotexist = 1
End sub

'*************************************** **********************
'Function name: function readfile (filepath)
'Function content: Read the file
'Input parameter: filepath: absolute path of the file to be read
'Return parameter: content of the file to be read.
'*************************************** **********************
Function readfile (filepath)


On Error resume next

Dim stm2


Set stm2 = server. Createobject ("ADODB. Stream ")
Listen 2.charset = "gb2312"
Ipv2.open
Secrets 2.loadfromfile filepath
Readfile = pai2.readtext
End Function

'*************************************** **********************
'Function name: function writefile (filepath, STR)
'Function content: Write File
'Input parameter: filepath: absolute path of the file to be read
'Str: content to be written
'Return parameter: None
'*************************************** **********************

Function writefile (filepath, STR)

On Error resume next


Set STM = server. Createobject ("ADODB. Stream ")
STM. charset = "gb2312"
STM. Open
STM. writetext Str
STM. savetofile filepath, adsavecreateoverwrite
End Function

'*************************************** **********************
'Function name: function copy (filepath_s, filepath_d)
'Function content: Read the file
'Input parameter: filepath_d: absolute path of the target file
'Filepath_s: source file path
'*************************************** **********************
Function copy (filepath_s, filepath_d)
On Error resume next
Dim stm2
Set stm2 = server. Createobject ("ADODB. Stream ")
Listen 2.charset = "gb2312"
Ipv2.open
Stm2.loadfromfile filepath_s
2.savetofile filepath_d, adsavecreateoverwrite
End Function

End Class

%>

author: Xu renlu
date: 2005-04-24
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.