用文件存取组件应用例

  说明:《网络程序设计-ASP》(蔡翠平主编、尚俊杰编著,清华大学出版社、北方交通大学出版社),第10章习题的实践题第1题:请试着用文件存取组件开发一个故事接龙网页。
  制作思路:在页面上显示一个用于输入添加内容的表单。并将文本文件作为包含文件插入网页,以便在网页上显示文本文件中的(添加)内容。

网页代码

<% Option Explicit %>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>在文本文件中添加内容</title>
<style type="text/css">
<!--
.base-4 {
font-size: 14px;
font-weight: bold;
}
body {
background-image: url(images/indtextb.jpg);
}
-->
</style>
</head>

<body>
<h1 align="center">在文本文件中添加内容</h1>
提示:下面是表单
<form id="form1" name="form1" method="post" action="" >
<table width="700" border="1" align="center" cellspacing="0" bordercolor="#0000FF" class="base-4">
<tr>
<td>添加内容</td>
<td><label>
<textarea name="textarea" cols="75" rows="10" class="base-4"></textarea>
</label></td>
</tr>
<tr>
<td><div align="right">
<input type="reset" name="Submit2" value="清除" >
</div></td>
<td><label>
<div align="center">
<input type="submit" name="Submit" value="添加" >
</div>
</label></td>
</tr>
</table>
</form>
提示:下面是将表单内容添加到文本文件中的VBSCRIPT
<%
dim text
text=request.Form("textarea")
dim fileobject
set fileobject=Server.CreateObject("scripting.filesystemobject")
dim textfile
set textfile=fileobject.opentextfile("F:\asptemp\Chapter10\test.txt",8,true)
textfile.writeline(text)
textfile.close
%>
提示:下面是用于控制显示文本文件内容位置的表格。
<table width="700" border="1" align="center" cellspacing="0" bordercolor="#FF0000" class="base-4">
<tr>
<td><h1 align="center">文本文件中现有的内容</h1></td>
</tr>
<tr>
<td><!--#include file ="test.txt"-->(注:这是包含文件代码)</td>
</tr>
</table>
</body>


主页                                  {其它

   

《花桥电脑书斋》-邱泳昱的个人主页
如需转载望能征求本人意见