<%@ page language="vb"%> <% @ import namespace=" system.io " %> <% @ import namespace=" system.data " %> <%@ import namespace="system.data.sqlclient" %> <script language = "vb" runat = "server"> dim lstrfilefolder as string dim lstrfilefolder_1 as string dim lstrfilenamepath as string dim lstrfilenamepath_1 as string sub uploadfile_clicked ( sender as object, e as eventargs ) dim lstrfilename as string
'dim lstrfilefolder as string dim cmdfilename as string '表单cmdfilename的值 cmdfilename = request("cmdfilename") ''' ''' ' 如果上传目录为空,就使用" upload "作为缺省上传目录 ' 获得上传到服务器的目录名称 if dir.value <> "" then lstrfilefolder_1 = dir.value & "/" lstrfilefolder = trim((server.mappath(""))) & "/" & dir.value & "/" else lstrfilefolder_1 = "upload/" lstrfilefolder = trim((server.mappath(""))) &"/upload/" end if
'只能上传.xls文件 if instr(path.getfilename ( lstrfilename ),".xls")=0 and instr(path.getfilename ( lstrfilename ),".xls")=0 and instr(path.getfilename ( lstrfilename ),".xls")=0 then messagenotxls.innerhtml = "只能上传.xls文件" messagenotxls.style("color") = "red" exit sub end if
if cmdfilename = "random" then dim lstrfilename111 as string = path.getfilename ( lstrfilename ) '获得原名 lstrfilename=now() lstrfilename=replace(lstrfilename,"-","") lstrfilename=replace(lstrfilename,":","") lstrfilename=replace(lstrfilename," ","") 'lstrfilename=lstrfilename+"." lstrfilename=lstrfilename & right(path.getfilename ( lstrfilename111 ),len(path.getfilename ( lstrfilename111 ))-(instr(path.getfilename ( lstrfilename111 ),"."))+1) else lstrfilename = path.getfilename ( lstrfilename ) end if ' 去掉目录信息,返回文件名称
' 判断上传目录是否存在,不存在就建立 if ( not directory.exists ( lstrfilefolder ) ) then directory.createdirectory ( lstrfilefolder ) end if
'添加记录信息到数据库,可以不要这步。 sub addtodb() dim myconnection as sqlconnection = new sqlconnection (configurationsettings.appsettings("connstr")) dim insertcmd as string = "insert into chaoqi (title,filepath) values (@title,@filepath)" dim mycommand as sqlcommand = new sqlcommand(insertcmd, myconnection)