What was the last time the file was modified? Probe the last update time of the file. Open and read a text file: This example opens the file "Textfile.txt"
Server Object
What was the last time the file was modified?
Probe the last update time of the file.
This sample code is as follows:
<body>
<%
Set fs = Server.CreateObject ("Scripting.FileSystemObject")
Set rs = fs. GetFile (Server.MapPath ("/example/aspe/demo_aspe_lastmodified.asp"))
Modified = Rs. DateLastModified
%>
The last modification time of this document is: <%response.write (modified)
Set rs = Nothing
Set fs = Nothing
%>
</body>
The results of this example run are as follows:
The last modified date for this document is: 2009-2-21 20:42:29
Open and read a text file
This example opens the file "Textfile.txt" for reading.
This sample code is as follows:
<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" > View this text file </a>
</p>
</body>
The results of this example run are as follows:
Hello World Line 1
Hello World Line 2
Hello World Line 3
View this text file
The contents of this text file are:
Hello World Line 1
Hello World Line 2
Hello World Line 3
Self-made click counter
This example reads a number from a file, adds 1 to the number, and then writes the number back to the file.
This sample code is as follows:
<%
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 was 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
%>
<body>
<p>
This page has been visited <%=fcount%> times.
</p>
</body>
The results of this example run are as follows:
This page has been accessed 12 times.