許多文件上傳組件并不能在vb中正常使用,我測試了chinaasp fileup,aspSmartupload,aspupload
enterprise,inotesupload等組件,均不能正
常使用。其主要原因,是因為在vb中沒有促發組件的OnStartPage過程。我們無法改寫這些組件,所以要自己編碼來解決這
個問題,記得以前有網友談過這個問題,但沒有代碼貼出來。
其實以前chinaasp上有個編寫web方式上載文件的組件的貼子(我一下找不了,這是我轉貼的地址
http://www.shinco.com/jjx/activeubb/NewsDetail.asp?id=134,稍微改寫一下就能在webclass中使用了
將原onstartpage過程改為
Public Sub OnStartPage(PassedRequest As Request)
'------------------定義局部變量----------------------
Dim varByteCount
Dim i
'---------------------------------------------------
'------------------建立ASP對象-----------------------
Set MyRequest = PassedRequest
'---------------------------------------------------
'------------------讀取客戶端傳來的全部數據-----------
varByteCount = MyRequest.TotalBytes
lngArrayLen = varByteCount - 1
ReDim binArray(varByteCount - 1)
binArray = MyRequest.BinaryRead(varByteCount)
'---------------------------------------------------
'--------------------獲取定界符---------------------
intDjfLen = 0
Do Until binArray(intDjfLen + 1) = 13
intDjfLen = intDjfLen + 1
Loop
ReDim binDjf(intDjfLen)
For i = 0 To intDjfLen
binDjf(i) = binArray(i)
Next
'---------------------------------------------------
End Sub
在webclass中使用
dim upload as new uploadfile
upload.onstartpage(request)
然后就可以用該類提供的方法了進行操作了,這個組件的功能比chinaasp upload要差些。但已經足夠使用了
其他改動
1、為了能用getthevalue方法正確取得input type 為checkbox,radio等的值,在
FindtheName中加入錯誤處理
Private Function FindTheName(nm As String) As Long
On Error GoTo FindTheNameError
'******************************參數說明*****************************
'* *
'* nm: 要尋找的 Form 元素名 *
'* 返回值: 成功—— 找到時的地址,失敗—— -1 *
'* *
'*******************************************************************
'------------------定義局部變量----------------------
Dim s As Long
Dim e As Long
Dim i As Long
Dim binTmp() As Byte
Dim strName As String
'---------------------------------------------------
'------------------尋找要取得值的Form 元素名------------------------
s = 0
Do While 1
s = FindTheDjf(s)
If s <> -1 Then
s = s + intDjfLen + 41
e = s
Do While binArray(e + 1) <> 34
e = e + 1
Loop
ReDim binTmp(e - s)
For i = s To e
binTmp(i - s) = binArray(i)
Next
strName = StrConv(binTmp, 64)
If StrComp(nm, strName) = 0 Then
FindTheName = e + 1
Exit Do
End If
Else
FindTheName = -1
Exit Do
End If
Loop
'--------------------------------------------------------------
Exit Function
FindTheNameError:
FindTheName = -1
End Function
2、刪除類聲明中的
Private MyScriptingContext As ScriptingContext定義