Open Directory Site ASP Tutorials

ASP | XML | VBScript | JavaScript | ADO | CSS | XMLDOM | PHP | Operating Systems

Home >> ASP >>ASP Server Object

ASP Server Object

 

Server Object

The Server Object is used to access properties and methods on the server.

Syntax

Server.property

Server.method

Properties

Property Description

ScriptTimeout Sets how long a script can run before it is terminated

Method

Method Description

CreateObject(type_of_object) Creates an instance of an object

Execute(path) Executes an .asp file from inside another .asp file. After

executing the called .asp file, you return the original .asp file

GetLastError() Returns an ASPError object that will describe the error

that occurred

HTMLEncode(string) Applies HTML encoding to a string

MapPath(path) Maps a relative or virtual path to a physical path

Transfer(path) Sends all of the state information to another .asp file for

processing. After the transferring is finished, you do not return

to the original .asp page

URLEncode(string) Applies URL encoding rules to a string

Examples

1.Last Modified

When was this file last modified?

Coding

<html>

<body>

<%

Set fs = Server.CreateObject("Scripting.FileSystemObject")

Set rs = fs.GetFile(Server.MapPath("demo_lastmodified.asp"))

modified = rs.DateLastModified

%>

This file was last modified on: <%response.write(modified)

Set rs = Nothing

Set fs = Nothing

%>

</body>

</html>

Output

This file was last modified on: 12.04.00 15:14:35

2.Open a TextFile for Reading

This example opens the file "Textfile.txt" for reading.

Coding

<html>

<body>

<%

Set FS = Server.CreateObject("Scripting.FileSystemObject")

Set RS = FS.OpenTextFile(Server.MapPath("text") & "\TextFile.txt",1)

While not rs.AtEndOfStream

Response.Write RS.ReadLine

Response.Write("<br>")

Wend

%>

<p>

<a href="text/textfile.txt"><img border="0" src="../images/btn_view_text.gif"></a>

</p>

</body>

</html>

Output

Hello World line 1

Hello World line 2

Hello World line 3

3. hit Counter

This example reads the content of "MyHitCounter.txt", adds 1 to the content, and writes the new number back to the file before the number is displayed. The result will not be displayed due to write access security.

Coding

<html>

<body>

<%

Set FS=Server.CreateObject("Scripting.FileSystemObject")

Set RS=FS.OpenTextFile(Server.MapPath("my_hitcounter.txt"), 8, True)

if not RS.AtEndOfStream then

fcount=RS.ReadAll

else

fcount=0

end if

fcount=fcount+100

Response.Write("This page has been visited <b>" & fcount & "</b> times.")

RS.Write fcount

RS.Close

Set RS=Nothing

Set FS=Nothing

%>

</body>

</html>

Cheap Web Hosting Articles - Web Site Design & Web Hosting Tutorials - Domain Hosting