在webclass中使用文件上传功能
webclass实例:http://www.shinco.com/jjx/wcnews/news.asp
许多文件上传组件并不能在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定义
