ASP Instance Tutorial: Server object

Source: Internet
Author: User
Tags object readline
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.



Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.