adostreame例子



<%
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'@ Object.Open(Source,[Mode],[Options],[UserName],[Password])
'@ [Mode] 指定打开模式
'1 adModeRead
'3 adModeReadWrite
'4194304 adModeRecursive
'16 adModeShareDenyNone
'4 adModeShareDenyRead
'8 adModeShareDenyWrite
'12 adModeShareExclusive
'0 adModeUnknown
'2 adModeWrite
'@ [Options] 指定打开的选项
'1 adOpenStreamAsync
'4 adOpenStreamFromRecord
'-1 adOpenStreamUnspecified

<%

'@ Object.Read(Bytes) 读取指定长度的二进制内容,不指定则读取全部
'@ Object.ReadText(Chars) 读取指定长度的文本,不指定则读取全部

'@ Object.Write(Buffer) 将指定内容装入对像中
'@ Object.Write(Data,[Options]) 将指定的文本数据装入对像中
'@ [Options] 写入的选项,可不指定
'0 adWriteChar
'1 adWriteLine

'@ Object.SaveToFile(FileName,[Options])
'@ SaveToFile 存取选项
'1 adSaveCreateNotExist
'2 adSaveCreateOverWrite

'@ Object.Flush 将缓存中的数据强制输出
'@ Object.setEOS() 将数据流设置为空
'@ Object.SkipLine(n) 跳过n行

'@ EOS 返回对像内数据是否为空
'@ LineSeparator 指定换行格式
'13 adCR
'-1 adCRLF
'10 adLF

'@ Type 指定或返回的数据类型
'1 adTypeBinary
'2 adTypeText

'@ Size 返回对像内数据的大小
'@ State 返加对像状态是否打开
'@ Charset 指定字符集
'@
'@ Lilo
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Function LocalRead(xPath,xChar)
On Error Resume Next
Set xStream = Server.CreateObject("ADODB.Stream")
With xStream
.Type = 1
.Mode = 3
.Open
.Position = 0
.LoadFromFile xPath
.Position = 0
.Type = 2
.Charset = xChar
LocalRead = .ReadText()
End With
End Function

Function LocalBinRead(xPath)
On Error Resume Next
Set xStream = Server.CreateObject("ADODB.Stream")
With xStream
.Type = 1
.Mode = 3
.Open
.Position = 0
.LoadFromFile xPath
.Position = 0
LocalBinRead = .Read
End With
End Function

Function ToChar(xConn,xChar)
On Error Resume Next
Set xStream = Server.CreateObject("ADODB.Stream")
With xStream
.Type = 1
.Mode = 3
.Open
.Position = 0
.Write xConn
.Position = 0
.Type = 2
.Charset = xChar
ToChar = .ReadText()
End With
End Function

Function RemoteRead(xPath)
On Error Resume Next
Set xmlDoc=Server.CreateObject("MSXML2.XMLHTTP")
xmlDoc.Open "GET",xPath,False
xmlDoc.Send()
If xmlDoc.readyState<>4 Then
Exit Function
End If
RemoteRead=xmlDoc.responseBody
Set xmlDoc=Nothing
End Function

Function LocalSave(xConn,xSave,xChar)
On Error Resume Next
Set xStream = Server.CreateObject("ADODB.Stream")
With xStream
.Type = xChar
.Open
If xChar = 1 Then .Write xConn Else .WriteText xConn
.SaveToFile xSave,2
.Close()
End With
Set xStream=Nothing
End Function

Function URLEncoding(vstrIn)
strReturn = ""
For i = 1 To Len(vstrIn)
ThisChr = Mid(vStrIn,i,1)
If Abs(Asc(ThisChr)) < &HFF Then
strReturn = strReturn & ThisChr
Else
innerCode = Asc(ThisChr)
If innerCode < 0 Then
innerCode = innerCode + &H10000
End If
Hight8 = (innerCode And &HFF00)\ &HFF
Low8 = innerCode And &HFF
strReturn = strReturn & "%" & Hex(Hight8) & "%" & Hex(Low8)
End If
Next
URLEncoding = strReturn
End Function
%>

<%
'@ 读取远程数据,可以是2进制,也可以是文本
xBody = RemoteRead("http://lilo.name/photo/index.asp")

<%

'@ 利用Stream转换字符集
'Response.write ToChar(xBody,"GB2312")

'@ 读取并显示本地2进制数据
Response.ContentType="Image/Gif"
Response.BinaryWrite LocalBinRead("D:\LiloWeb\WWWRoot\asp\001.gif")
Response.Flush

'@ 读取并输出本地文本数据
'Response.write LocalRead("D:\LiloWeb\WWWRoot\asp\001.txt","GB2312")
%>

 


豫ICP备12024565号-1   E-mail:admin@hlc8.com