FileSystemObject组件新建读取添加修改删除功能实例


<%@LANGUAGE="VBSCRIPT" CODEPAGE="936"%> 
<html> 
<head> 
<meta http-equiv="Content-Type" content="text/html; charset=gb2312"> 
<title>FileSystemObject组件应该实例</title> 
</head>

<body> 
<input name="B0" type="button" value="创建文本文件" onClick="window.location='test1.asp?type=crea'"> 
<input name="B1" type="button" value="读取文件内容" onClick="window.location='test1.asp?type=read'"> 
<input name="B2" type="button" value="添加文件内容" onClick="window.location='test1.asp?type=add'"> 
<input name="B3" type="button" value="修改文件内容" onClick="window.location='test1.asp?type=edit'"> 
<input name="B4" type="button" value="删除文件内容" onClick="window.location='test1.asp?type=dele'"> 
<% 
read="michael.txt" 
'获取文件真实路径 
read=LEFT(Server.MapPath(Request.ServerVariables("PATH_INFO")),InstrRev(Server.MapPath(Request.ServerVariables("PATH_INFO")),"\")) & read 
'response.write "文件路径:" & read & "<br>" '输出文件真实路径 
%> 
<hr> 
<%if request.querystring("type")="crea" then%> 
<form action="test1.asp?type=crea" method="post" name="form1"> 
请输入文件名 : <input name="T1" size="45">.txt<br> 
请输入文件内容:<textarea name="D1" cols="50" rows="5"></textarea> 
<input name="bu" type="Submit" value="提交"> 
</form> 
<%end if%> 
<%if request.querystring("type")="add" then%> 
<form action="test1.asp?type=add" method="post" name="form1"> 
<textarea name="D1" cols="70" rows="5"></textarea> 
<input name="bu" type="Submit" value="提交"> 
</form> 
<%end if%> 
<% 
if request.querystring("type")="edit" then 
Set fs=CreateObject("Scripting.FileSystemObject") 
if fs.FileExists(server.mappath("michael.txt")) then 
Set ts=fs.OpenTextFile(server.mappath("michael.txt")) 
%> 
<form action="test1.asp?type=add" method="post" name="form1"> 
<textarea name="D1" cols="70" rows="5"><%=ts.ReadLine%></textarea> 
<input name="bu" type="Submit" value="提交"> 
</form> 
<% 
else 
response.write "找不到此文件" 
end if 
end if 
%> 
<% 
if request.querystring("type")="crea" and request.form<>"" then '创建新的文件 
Set fs=CreateObject("Scripting.FileSystemObject") 
if fs.FileExists(server.mappath(request.form("T1")& ".txt")) then '判断文件是否存在 
response.write "<script>alert('该文件已经存在');window.location='test1.asp?type=crea';</script>" 
else 
Set ts=fs.CreateTextFile(server.mappath(request.form("T1")& ".txt"),True) 
ts.close 
Set ts=fs.OpenTextFile(server.mappath(request.form("T1")& ".txt"),2,True) 
ts.WriteLine(request.form("D1")) '写入文件内容 注:WriteLine是加入内容并换行,Write是加入内容不换行 
ts.close 
response.write "<script>alert('创建文件成功');window.location='test1.asp?type=read';</script>"

end if 
set fs=nothing 
end if 

%>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值