使用Active X服务器组件 ASP.docx
- 文档编号:28075396
- 上传时间:2023-07-08
- 格式:DOCX
- 页数:30
- 大小:68.09KB
使用Active X服务器组件 ASP.docx
《使用Active X服务器组件 ASP.docx》由会员分享,可在线阅读,更多相关《使用Active X服务器组件 ASP.docx(30页珍藏版)》请在冰豆网上搜索。
使用ActiveX服务器组件ASP
实验
成绩
实验评阅教师签名
简
要
评
语
华北科技学院管理系
实验报告册
共6页第1页
实验报告
实验时间:
2011年9月19日1、2节
一、实验运行环境
WindowsXPServer计算机系统;IIS、Dreamweaver8等。
二、实验目的
熟悉VBScript的语法、掌握服务器端利用VBScript编程的基本方法。
三、实验要求
学生掌握VB语言的语法特点和内置的常用函数的用法;对程序的结构(顺序、分支、循环、过程)的概念和语法比较清晰;具备基本的编写程序的能力。
四、实验内容和步骤
1、综合运用FileAccess组件,建立一个文件管理系统。
文件管理系统具有以下功能:
Ø创建目录
Ø删除目录
Ø创建文件
Ø删除文件
Ø编辑文件
Ø浏览和下载文件
Ø查看文件属性
Ø查看子目录
Ø返回上一级目录和根目录
代码:
<%@Language=VBscript%>
<%
Response.Buffer=true
OnErrorResumeNext
Server.ScriptTimeOut=1000
Response.Expires=0
DimStartTime,IsReplace
IsReplace=true'是否过滤编辑时文件的标记,如不过滤遇到有
StatrTime=Timer()
%>
<%
'****************************************
'函数定义部分开始
'****************************************
'*******************************************
'过程作用:
判断服务器是否支持FSO
'*******************************************
SubIsErr()
IfErr=-2147221005Then
Response.write"这台服务器不支持FSO,故本程序无法运行"
Response.end
EndIf
EndSub
'*******************************************
'函数作用:
取得文件的后缀名
'*******************************************
FunctionUpDir(ByValD)
DimUDir
IfLen(D)=0thenExitFunction
UDir=Left(D,InStrRev(D,"\")-1)
UpDir=UDir
EndFunction
'*******************************************
'函数作用:
取得当前页的URL,
'为文件添加正确的链接
'*******************************************
FunctionFileUrl(url,D)
DimPageUrl,PUrl
PageUrl="http:
//"&Request.ServerVariables("SERVER_NAME")
PUrl=Left(Request.ServerVariables("URL"),InStrRev(Request.ServerVariables("Url"),"/"))
PageUrl=PageUrl&Purl&Mid(D,2,Len(D))&"/"&url
FileUrl=PageUrl
EndFunction
'*******************************************
'函数作用:
格式化文件的大小
'*******************************************
FunctionGetFileSize(size)
DimFileSize
FileSize=size/1024
FileSize=FormatNumber(FileSize,2)
IfFileSize<1024andFileSize>1then
GetFileSize="
ElseIfFileSize>1024then
GetFileSize="
Else
GetFileSize="
EndIf
EndFunction
'*******************************************
'函数作用:
取得文件的后缀名
'*******************************************
FunctionGetExtensionName(name)
DimFileName
FileName=Split(name,".")
GetExtensionName=FileName(Ubound(FileName))
EndFunction
'*******************************************
'函数作用:
返回文件类型
'*******************************************
FunctionGetFileIcon(name)
DimFileName,Icon
FileName=Lcase(GetExtensionName(name))
SelectCaseFileName
Case"asp"
Icon="asp"
Case"bmp"
Icon="bmp"
Case"doc"
Icon="doc"
Case"exe"
Icon="exe"
Case"gif"
Icon="gif"
Case"jpg"
Icon="jpg"
Case"chm"
Icon="chm"
Case"htm","html"
Icon="htm"
Case"log"
Icon="log"
Case"mdb"
Icon="mdb"
Case"swf"
Icon="swf"
Case"txt"
Icon="txt"
Case"wav"
Icon="wav"
Case"xls"
Icon="xls"
Case"rar","zip"
Icon="zip"
Case"css"
Icon="css"
CaseElse
Icon="none"
EndSelect
GetFileIcon=Icon
EndFunction
'*******************************************
'过程作用:
删除选定的文件或文件夹
'*******************************************
SubDelAll()
DimFolderId,FileId,ThisDir,FileNum,FolderNum,FilePath,FolderPath
FolderId=Split(Request.Form("FolderId"),",")
FileId=Split(Request.Form("FileId"),",")
ThisDir=trim(Request.Form("ThisDir"))
FileNum=0
FolderNum=0
IfUbound(FolderId)<>-1then'删除文件夹
Fori=0toUbound(FolderId)
FolderPath=Server.MapPath(".")&ThisDir&"\"&trim(FolderId(i))
IfFso.FolderExists(FolderPath)then
Fso.DeleteFolderFolderPath,true
FolderNum=FolderNum+1
EndIf
Next
EndIf
IfUbound(FileId)<>-1then'删除文件
Forj=0toUbound(FileId)
FilePath=Server.MapPath(".")&ThisDir&"\"&trim(FileId(j))
IfFso.FileExists(FilePath)then
Fso.DeleteFileFilePath,true
FileNum=FileNum+1
EndIf
Next
EndIf
Response.write""
EndSub
'*******************************************
'过程作用:
使选定的文件或文件夹改名
'*******************************************
SubRname()
DimThisDir,FolderName,NewName,OldName
ThisDir=Trim(Request.Form("ThisDir"))
FolderName=Trim(Request.Form("FolderId"))
FileName=Trim(Request.Form("FileId"))
NewName=Trim(Request.QueryString("NewName"))
Iflen(FolderName)<>0then'文件夹改名
NewName1=Server.MapPath(".")&ThisDir&"\"&NewName
OldName=Server.MapPath(".")&ThisDir&"\"&FolderName
IfnotFso.FolderExists(NewName1)then
Fso.MoveFolderOldName,NewName1
Response.write""
Else
Response.write""
EndIf
EndIf
Iflen(FileName)<>0then'文件改名
NewName1=Server.MapPath(".")&ThisDir&"\"&NewName
OldName=Server.MapPath(".")&ThisDir&"\"&FileName
IfnotFso.FileExists(NewName1)then
Fso.MoveFileOldName,NewName1
Response.write""
Else
Response.write""
EndIf
EndIf
EndSub
'*******************************************
'过程作用:
新建文件
'*******************************************
SubNewFile()
DimNewFile,NewFilePath
NewFilePath=Trim(Request.Form("ThisDir"))
NewFile=Trim(Request.Form("NewFileName"))
NewFilePath=Server.MapPath(".")&NewFilePath&"\"&NewFile
IfnotFso.FileExists(NewFilePath)andnotFso.FolderExists(NewFilePath)then
SetFsoFile=Fso.CreateTextFile(NewFilePath)
FsoFile.Writeline
FsoFile.close
SetFsoFile=nothing
Response.write""
Else
Response.write""
Endif
EndSub
'*******************************************
'过程作用:
新建文件夹
'*******************************************
SubNewFolder()
DimNewFolder,NewFolderPath
NewFolderPath=Trim(Request.Form("ThisDir"))
NewFolder=Trim(Request.Form("NewFolderName"))
NewFolderPath=Server.MapPath(".")&NewFolderPath&"\"&NewFolder
IfnotFso.FolderExists(NewFolderPath)then
Fso.CreateFolder(NewFolderPath)
Response.write""
Else
Response.write""
Endif
EndSub
'*******************************************
'过程作用:
css样式
'*******************************************
SubCss()
%>
.fonts{font-size:
9pt;line-height:
25px}
.button{padding:
2px;
height:
20px;
background-color:
#FF9900;
color:
#ffffff;
border:
1pxsolid#333333;
font-size:
12px;
font-family:
"宋体";
}
.TextBox{
border-top-width:
1px;
border-right-width:
1px;
border-bottom-width:
1px;
border-left-width:
1px;
border-top-style:
solid;
border-right-style:
solid;
border-bottom-style:
solid;
border-left-style:
solid;
border-top-color:
#666666;
border-right-color:
#CCCCCC;
border-bottom-color:
#CCCCCC;
border-left-color:
#666666;
padding:
2px;
height:
300px;
font-size:
12px;
font-family:
"宋体";
}
.InputBox{
border-top-width:
1px;
border-left-width:
1px;
border-right-width:
1px;
border-bottom-width:
1px;
border-top-color:
#000000;
border-left-color:
#000000;
border-bottom-color:
#000000;
border-right-color:
#000000;
padding:
2px;
height:
20px;
}
Input,Select,TextArea{
font-family:
"宋体";
font-size:
12px;
text-decoration:
none;
}
a:
link{color:
#000000;text-decoration:
none}
a:
visited{color:
#000000;text-decoration:
none}
a:
hover{color:
#FF0000;text-decoration:
underline}
<%
EndSub
'*******************************************
'过程作用:
编辑文件
'*******************************************
SubEdit()
DimFilePath,FileName,action
SetFso=Server.CreateObject("Scripting.FileSystemObject")
IsErr
action=Trim(Request.QueryString("action"))
Ifaction=("Save")then'保存文件
DimFileSave
FilePath=trim(Request.QueryString("FilePath"))
FileAll=trim(Request.Form("FileAll"))
IfIsReplacethenFileAll=Replace(FileAll,"\\textarea\\","textarea")
IfFso.FileExists(FilePath)then
SetFileSave=Fso.OpenTextFile(FilePath,2)
FileSave.Write(FileAll)
FileSave.Close
Response.write""
Else
Response.write""
EndIf
ElseIfaction=("Edit")then'读取文件
DimFileAll
FilePath=Trim(Request.Form("ThisDir"))
FileName=Trim(Request.Form("FileId"))
FilePath1=Server.MapPath(".")&FilePath&"\"&FileName
IfFso.FileExists(FilePath1)then
SetFileOpen=Fso.OpenTextFile(FilePath1,1)
FileAll=FileOpen.ReadAll
FileOpen.close
IfIsReplacethenFileAll=Replace(FileAll,"textarea","\\textarea\\")
Else
Response.write""
EndIf
%>
<%CallCss%>
fun
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 使用Active X服务器组件 ASP 使用 Active 服务器 组件