在我开始做自己的组件以前,我想知道其他类似控件提供什么样的功能.因此我看啦另外3个著名的组件:
the upload component of Software Artisans, the upload component of ASPUpload,
and the Microsoft Posting Acceptor.
Set objUpload = Server.CreateObject("pjUploadFile.clsUpload")
If Err.Number <> 0 Then
Response.Write "The component wasn't registered"
Else
varResult = objUpload.DoUpload (lngMaxFileBytes, strUploadPath)
Set objUpload = Nothing
Dim i
For i = 0 to UBound(varResult,1)
Response.Write varResult(i,0) & " : " & varResult(i,1) & "<br>"
Next
End If
End If
%>
在这里设置下面两个变量:
lngMaxFileBytes - 文件最大字节数, 和 strUploadPath -文件上传位置.我也增加了错误处理程序检查是否装入组件在网服务器上适当注册.这是我做的处理唯一的一个错误.如果任何另外的错误发生,可以再加入处理它.最后,再声明varReturn.这变量用来接受组件的返回值.这返回值应该包含所有的表单元件名字和他们的值.你能看见FOR NEXT loop中的程序,这返回值必须是一数组.
首先,先添加一个引用,在菜单条上选定添加引用项,选中
Active Server Pages Object library.(参阅步骤2).
步骤2:
工程引用
通过这个库我们能使用asp的request的请求对象.为保证能使用,要用如下代码:
Option Explicit
Private MyScriptingContext As ScriptingContext
Private MyRequest As Request
Private MyResponse As Request
Public Sub OnStartPage(PassedScriptingContext As ScriptingContext)
Set MyScriptingContext = PassedScriptingContext
Set MyRequest = MyScriptingContext.Request
Set MyResponse = MySriptingContext.Response
End Sub
Private MyScriptingContext As ScriptingContext
Private MyRequest As Request
Private MyResponse As Request
Public Sub OnStartPage(PassedScriptingContext As ScriptingContext)
Set MyScriptingContext = PassedScriptingContext
Set MyRequest = MyScriptingContext.Request
Set MyResponse = MySriptingContext.Response
End Sub
Public Function DoUpload (ByVal lngMaxFileBytes As Long, _
ByVal strUploadPath As String) As Variant
Dim varByteCount As Variant
Dim varHTTPHeader As Variant
'Count total bytes in HTTP-header
varByteCount = MyRequest.TotalBytes
'Conversion of bytes to Unicode
varHTTPHeader = StrConv(MyRequest.BinaryRead(varByteCount), vbUnicode)
'Write HTTPHeader
MyResponse.Write varHTTPHeader
Function End
现在让我们测试这些代码的.为这测试我使用用了一个.txt 文件 "warp11.txt" 那包含的下面一句话:
"Warp11 builds state-of-the-art applications at the speed of light."