fso|教程|應用執行個體
終結FSO應用執行個體篇-FSO使用教程8
通過前面8個相關FSO詳細教程,下面我們結合學過的東西,製做一個簡單的產生HTML文文章系統,包含有檔案標題和內容,並帶有修改文章功能。
包含檔案:
AddArticle.html '文章內容錄入表單檔案
ModiArticle.asp '修改檔案內容檔案
SaveArticle.asp '儲存新增內容檔案
為了方便教程示範,我們在源碼中統一產生的HTML檔案名稱為"FsoToHtml.Html"
'AddArticle.html 原始碼
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>添加新文章</title>
</head>
<body>
<form method="post" name="thefrm" action="SaveArticle.asp">
文章標題:<input name="Title" type="text" value="" size="30">
<hr />
文章內容:<br />
<textarea name="content" cols="60" rows="20"></textarea>
<br />
<input type="submit" name="Submit" value="FSO產生寫入HTML" />
</form>
</body>
</html>
'SaveArticle.asp 源碼
<%
'================================================
'作者:阿里西西
'網址:http://www.alixixi.com/
'源碼:FSO產生HTML檔案樣本
'時間:2005年12月17日
'================================================
Set fs = Server.CreateObject("Scripting.FileSystemObject")
File = Server.MapPath("FsoToHtml.Html")
Set txt = fs.OpenTextFile(File,2,True)
HtmlFile = "文章標題:"&Request.Form("Title") & "<hr />" & Request.Form("Content")&"" '擷取表單提交的內容
txt.Write HtmlFile
Set fs = nothing
Response.write "<a href=""FsoToHtml.Html"">成功組建檔案"&File&"</a><p>"
Response.write "<a href=""ModiArticle.asp"">修改HTML檔案內容</a>"
%>
ModiArticle.asp '源碼
<%
'================================================
'作者:阿里西西
'網址:http://www.alixixi.com/
'源碼:FSO修改已產生的HTML檔案樣本
'時間:2005年12月17日
'================================================
Set fs = Server.CreateObject("Scripting.FileSystemObject")
File = Server.MapPath("FsoToHtml.Html")
Set txt = fs.OpenTextFile(File,1,True)
If Not txt.atEndOfStream Then
Content = txt.ReadAll
End If
Set fs = nothing
Title = split(Content,"<hr />")(0) '通過<hr />分隔擷取文章標題
Text = split(Content,"<hr />")(1) '通過<hr />分隔擷取文章內容
%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>添加新文章</title>
</head>
<body>
<form action="SaveArticle.asp" method="post" name="thefrm">
文章標題:
<input name="Title" type="text" value="<%=Title%>" size="30">
<hr />
文章內容:<br />
<textarea name="content" cols="60" rows="20"><%=Text%></textarea>
<br />
<input type="submit" name="Submit" value="FSO產生寫入HTML" />
</form>
</body>
</html>
通過以上三個檔案,我們就實現了產生HTML檔案,並帶修改功能的小文章系統了。趕快動手來實戰吧
到此,FSO教程篇已終結,通過這9篇的基礎文章,舉一反三,你可以寫出更強大的FSO應用程式或通用類出來。如果你對本教程有什麼建議或意見歡迎在本站留言或論壇發表評論。
阿里西西
http://www.alixixi.com
2005年12月17日