ASP執行個體教程:Server對象

來源:互聯網
上載者:User
此檔案最後被修改的時間是?探測檔案的最後更新時間。開啟並讀取某個文字檔:本例會開啟檔案"Textfile.txt"

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 次。



聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.