Asp教程

通过asp实例结合结合ACCESS,MSSQL来更好的深入Asp学习 - 爬坡者

« css自动换行总结解决SQL注入的简单函数 »

FSO读写

我写过
一个
写文件cfile.asp
-----------------------------
<html>
<head>
<title>创建文档</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<link rel="stylesheet" href="forum_admin.css" type="text/css">
<script language="JavaScript">
<!--

function pb()
{
if(window.confirm("确定要执行操作吗?")){

  document.all.myform.submit();   }
else return ;
}
//-->
</script>
</head>

<body>
<%
dim nam,text,ty,myfile,link
path = "cfile.asp"
nam = trim(request.form("name"))
text = request.form("text")
ty = request.Form("ty")

sub crt()
     link = Server.MapPath (foldername) & "\nextlink.txt"  '文件路径
     set listfile = FileObject.OpenTextFile(link,8,false)
     listfile.WriteLine "rfile.asp?name=" & nam & "&ty=" & ty & "        " & nam & ty    '写入

end sub

if name<>"" or text<>"" then
set FileObject = Server.CreateObject ("Scripting.FileSystemObject")
path=request.ServerVariables("SCRIPT_NAME") 
foldername=FileObject.GetParentFolderName(path)
textfile = Server.MapPath(foldername) & "\" & nam & ty 
    if trim(request("action"))="add" then                 '添加文件
                
                set myfile = FileObject.CreateTextFile(textfile,true,false)
              
                call crt()
                myfile.WriteLine text
                set myfile = nothing
                response.Write "文档" & nam & ty & "创建成功!<br>"
                response.Write "<p><a href="& chr(34) & path & chr(34) & ">返回</a></p>"
    elseif trim(request("action")) = "mody" then              '修改文件
       set myfile = FileObject.CreateTextFile(textfile,true,false)
       myfile.WriteLine text
       set myfile = nothing
       response.Write "文档" & nam & ty & "修改成功!<br>"
       response.Write "<p><a href="& chr(34) & path & chr(34) & ">返回</a></p>"
   end if
else
%>

<center>

<form action = "<%=path%>?action=add" method = "post" name="myform">
<table cellpadding=3 cellspacing=1 width="100%"  class="tableBorder">
  <tr>
      <th aligh=left>创建文件:</th>
  </tr>
  <tr><td class=forumRow>文件名:<input name="name" type="text" maxlength="72">
      类型:  
      <select name="ty" size="1">
        <option value="" selected></option>
        <option value=".html">.html</option>
        <option value=".htm">.htm</option>
        <option value=".txt">.txt</option>
        <option value=".asp">.asp</option>
        <option value=".php">.php</option>
        <option value=".js">.js</option>
      </select></td>
   </tr>
   <tr>
     <td class=forumRowHighlight>代码如下:</td>
   </tr>
   <tr>
     <td class=forumRow><textarea name="text" cols="110" rows="17"></textarea></td>
   </tr>
   <tr><td class=forumRowHighlight height=5><input type="button" value="创建文档" onclick="pb()"></td>
   </tr>
</table>
</form>
</center>
<%end if%>
</body><html>
------------------------------
读文件 rfile.asp
接上面的
<%
dim txt
txt=""
nam= trim(request("name"))
ty = trim(request("ty"))
text=""
if nam<>"" or ty<>"" then

Set fileObject = Server.CreateObject ("SCRIPTING.FileSystemObject")

path=request.ServerVariables("SCRIPT_NAME") 

foldername=FileObject.GetParentFolderName(path)

testfile = Server.MapPath(foldername) & "\" & nam & ty 

set Instream=FileObject.OpenTextFile(testfile,1,false,false)

while not Instream.AtEndOfStream
  txt=txt&Instream.ReadAll

wend%>



<html>
<head>
<title>修改文档</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<link rel=stylesheet href="Forum_admin.css" type=text/css>
</head>
<script language="JavaScript">
function pb()
{
if(window.confirm("确定要执行操作吗?")){

  document.all.myform.submit();   }
else return ;
}

function showerror(){
if(myform.name.value!="<%=nam%>")

window.alert("文件名不可改!")

myform.name.value="<%=nam%>"

}
</script>
<body onmousemove="showerror()" topmargin=2>




<form action = "cfile.asp?action=mody" method = "post" name="myform">
<table cellpadding=3 cellspacing=1 width="100%"  class="tableBorder">
  <tr>
      <th>创建文件:</th></tr>
  <tr>
      <td class=ForumRow>文件名:<input name="name" type="text" maxlength="72" value="<%=nam%>" onmouseout="showerror()">
      类型:   
      <select name="ty" size="1">
        <option value="<%=ty%>" selected><%=ty%></option>
              </select></td>
   </tr>
   <tr>
     <td class=ForumRowHighlight>代码如下:</td>
   </tr>
   <tr>
     <td class=ForumRow><textarea name="text" cols="112" rows="20"><%=txt%></textarea></td>
   </tr>
   <tr>
     <td class=ForumRowHighlight><input type="button" value="保存" onclick="pb()">        <input type=button value="预览" onclick="window.open('<%="http://"&request.ServerVariables("Local_ADDR")&foldername&"/"&nam&ty%>')"></td>
   </tr>
</table></form>
<p>  </p>
</body>
</html>
<%else
response.write "<a href="&chr(34)&"javascript:history.go(-1)"&chr(34)&">返回</a>"
end if%>

发表评论:

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。

最新评论及回复

最近发表

Powered By Z-Blog 1.8 Spirit Build 80710

Copyright 2007-2008 papozhe.com [asp教程] All Rights Reserved.
浙ICP备07030537号
免责申明:所有文章除特别声明,均来自网上,主要为学习用!内容仅供参考,版权归原作者。如侵犯您利益,请来信告知.
Email:papozhe$Gmail.com QQ:76336503