ASP 網頁設計

技巧

Server 對象

此文件最後被修改的時間是?

探測文件的最後更新時間。

本示例代碼如下:

<html>
<body>
<%
Set fs = Server.CreateObject("Scripting.FileSystemObject")
Set rs = fs.GetFile(Server.MapPath("/example/aspe/demo_aspe_lastmodified.asp"))
modified = rs.DateLastModified
%>
本文件的最後修改時間是:<%response.write(modified)
Set rs = Nothing
Set fs = Nothing
%>
</body>
</html>

本實例運行結果如下:

本文件的最後修改時間是:2009-2-21 20:42:29

打開並讀取某個文本文件

本例會打開文件"Textfile.txt"以供讀取。

本示例代碼如下:

<html>
<body>
<%
Set FS = Server.CreateObject("Scripting.FileSystemObject")
Set RS = FS.OpenTextFile(Server.MapPath("/example/aspe") & "\textfile.txt",1)
While not rs.AtEndOfStream
      Response.Write RS.ReadLine
      Response.Write("<br />")
Wend
%>
<p>
<a href="/example/aspe/textfile.txt">查看此文本文件</a>
</p>
</body>
</html>

本實例運行結果如下:

Hello World line 1
Hello World line 2
Hello World line 3
查看此文本文件

此文本文件內容是:

Hello World line 1
Hello World line 2
Hello World line 3

自製的點擊計數器

本例可從某文件中讀取一個數字,並在此數字上累加1,然後將此數寫回這個文件。

本示例代碼如下:

<%
Set FS=Server.CreateObject("Scripting.FileSystemObject")
Set RS=FS.OpenTextFile(Server.MapPath("/example/aspe/counter.txt"), 1, False)
fcount=RS.ReadLine
RS.Close
fcount=fcount+1
'This code is disabled due to the write access security on our server:
'Set RS=FS.OpenTextFile(Server.MapPath("counter.txt"), 2, False)
'RS.Write fcount
'RS.Close
Set RS=Nothing
Set FS=Nothing
%>
<html>
<body>
<p>
本頁已被訪問了 <%=fcount%>  次。
</p>
</body>
</html>

本實例運行結果如下:

本頁已被訪問了 12 次。

arrow
arrow
    全站熱搜
    創作者介紹
    創作者 dettori 的頭像
    dettori

    Web Design

    dettori 發表在 痞客邦 留言(0) 人氣()