Vous êtes sur la page 1sur 39

1.

<html>
<body>
<%
response.write("Hello World!")
%>
</body>
</html>
2.
<html>
<body>
<%
response.write("<h2>You can use HTML tags to format the text!</h2>")
%>
<%
response.write("<p style='color:#0000ff'>This text is styled with the style attribute!
</p>")
%>
</body>
</html>
3.
<html>
<body>
<%
dim name
name="Donald Duck"
response.write("My name is: " & name)
%>
</body>
</html>
4.
<html>
<body>
<%
Dim famname(6),i
famname(1) = "Jan Egil"
famname(2) = "Tove"
famname(3) = "Hege"
famname(4) = "Stale"
famname(5) = "Kai Jim"
famname(6) = "Borge"
For i = 1 to 6
response.write(famname(i) & "<br />")

Next
%>
</body>
</html>
5.
<html>
<body>
<%
dim i
for i=1 to 6
response.write("<h" & i & ">Header " & i & "</h" & i & ">")
next
%>
</body>
</html>
6.
<html>
<body>
<%
dim h
h=hour(now())
response.write("<p>" & now())
response.write(" (Norwegian Time) </p>")
If h<12 then
response.write("Good Morning!")
else
response.write("Good day!")
end if
%>
</body>
</html>
7.
<%@ language="javascript" %>
<html>
<body>
<%
var d=new Date()
var h=d.getHours()
Response.Write("<p>")
Response.Write(d + " (Norwegian Time)")
Response.Write("</p>")
if (h<12)
{
Response.Write("Good Morning!")
}

else
{
Response.Write("Good day!")
}
%>
</body>
</html>
8.
<html>
<body>
Today's date is: <%response.write(date())%>.
<br>
The server's local time is: <%response.write(time())%>.
</body>
</html>
9.
<html>
<body>
<p>
VBScripts' function <b>WeekdayName</b> is used to get a weekday:
</p>
<%
response.Write(WeekDayName(1))
response.Write("<br>")
response.Write(WeekDayName(2))
%>
<p>Abbreviated name of a weekday:</p>
<%
response.Write(WeekDayName(1,true))
response.Write("<br>")
response.Write(WeekDayName(2,true))
%>
<p>Current weekday:</p>
<%
response.Write(WeekdayName(weekday(date)))
response.Write("<br>")
response.Write(WeekdayName(weekday(date), true))
%>
</body>
</html>
10.
<html>
<body>

<p>VBScripts' function <b>MonthName</b> is used to get a month:</p>


<%
response.Write(MonthName(1))
response.Write("<br>")
response.Write(MonthName(2))
%>
<p>Abbreviated name of a month:</p>
<%
response.Write(MonthName(1,true))
response.Write("<br>")
response.Write(MonthName(2,true))
%>
<p>Current month:</p>
<%
response.Write(MonthName(month(date)))
response.Write("<br>")
response.Write(MonthName(month(date), true))
%>
</body>
</html>
11.
<html>
<body>
Today it is
<%response.write(WeekdayName(weekday(date)))%>,
<br />
and the month is
<%response.write(MonthName(month(date)))%>
</body>
</html>
12.
<html>
<body>
<p>Countdown to year 3000:</p>
<p>
<%millennium=cdate("1/1/3000 00:00:00")%>
It is
<%response.write(DateDiff("yyyy", Now(), millennium))%>
years to year 3000!
<br>
It is
<%response.write(DateDiff("m", Now(), millennium))%>

months to year 3000!


<br>
It is
<%response.write(DateDiff("ww", Now(), millennium))%>
weeks to year 3000!
<br>
It is
<%response.write(DateDiff("d", Now(), millennium))%>
days to year 3000!
<br>
It is
<%response.write(DateDiff("h", Now(), millennium))%>
hours to year 3000!
<br>
It is
<%response.write(DateDiff("n", Now(), millennium))%>
minutes to year 3000!
<br>
It is
<%response.write(DateDiff("s", Now(), millennium))%>
seconds to year 3000!
</p>
</body>
</html>
13.
<html>
<body>
<%
response.write(DateAdd("d",30,date()))
%>
<p>
Syntax for DateAdd: DateAdd(interval,number,date). You can use <b>DateAdd</b>
to for example calculate a date 30 days from today.
</p>
</body>
</html>
14.
<html>
<body>
<%
response.write(FormatDateTime(date(),vbgeneraldate))
response.write("<br />")
response.write(FormatDateTime(date(),vblongdate))
response.write("<br />")
response.write(FormatDateTime(date(),vbshortdate))
response.write("<br />")
response.write(FormatDateTime(now(),vblongtime))

response.write("<br />")
response.write(FormatDateTime(now(),vbshorttime))
%>
<p>
Syntax for FormatDateTime: FormatDateTime(date,namedformat).
</p>
</body>
</html>
15.
<html>
<body>
<%
somedate="10/30/99"
response.write(IsDate(somedate))
%>
</body>
</html>
16.
<html>
<body>
<%
name = "Bill Gates"
response.write(ucase(name))
response.write("<br>")
response.write(lcase(name))
%>
</body>
</html>
17.
<html>
<body>
<%
name = " W3Schools "
response.write("visit" &
response.write("visit" &
response.write("visit" &
response.write("visit" &
%>
</body>
</html>

name & "now<br />")


trim(name) & "now<br />")
ltrim(name) & "now<br />")
rtrim(name) & "now")

18.
<html>
<body>
<%
sometext = "Hello Everyone!"
response.write(strReverse(sometext))
%>
</body>
</html>
19.
<html>
<body>
<%
i = 48.66776677
j = 48.3333333
response.write(Round(i))
response.write("<br>")
response.write(Round(j))
%>
</body>
</html>
20.
<html>
<body>
<%
randomize()
response.write(rnd())
%>
</body>
</html>
21.
<html>
<body>
<%
sometext="Welcome to this Web"
response.write(Left(sometext,5))
response.write("<br>")
response.write(Right(sometext,5))
%>
</body>
</html>

22.
<html>
<body>
<%
sometext="Welcome to this Web!!"
response.write(Replace(sometext, "Web", "Page"))
%>
</body>
</html>
23.
<html>
<body>
<%
sometext="Welcome to this Web!!"
response.write(Mid(sometext, 9, 2))
%>
</body>
</html>
24.
<html>
<head>
<%
sub vbproc(num1,num2)
response.write(num1*num2)
end sub
%>
</head>
<body>
<p>
You can call a procedure like this:
</p>
<p>
Result: <%call vbproc(3,4)%>
</p>
<p>
Or, like this:
</p>
<p>
Result: <%vbproc 3,4%>
</p>
</body>
</html>

25.
<%@ language="javascript" %>
<html>
<head>
<%
function jsproc(num1,num2)
{
Response.Write(num1*num2)
}
%>
</head>
<body>
<p>
Result: <%jsproc(3,4)%>
</p>
</body>
</html>
26.
<html>
<head>
<%
sub vbproc(num1,num2)
Response.Write(num1*num2)
end sub
%>
<script language="javascript" runat="server">
function jsproc(num1,num2)
{
Response.Write(num1*num2)
}
</script>
</head>
<body>
<p>Result: <%call vbproc(3,4)%></p>
<p>Result: <%call jsproc(3,4)%></p>
</body>
</html>
27.
<html>
<body>
<form action="demo_reqquery.asp" method="get">
Your name: <input type="text" name="fname" size="20" />
<input type="submit" value="Submit" />
</form>
<%
dim fname
fname=Request.QueryString("fname")

If fname<>"" Then
Response.Write("Hello " & fname & "!<br />")
Response.Write("How are you today?")
End If
%>
</body>
</html>
28.
<html>
<body>
<form action="demo_simpleform.asp" method="post">
Your name: <input type="text" name="fname" size="20" />
<input type="submit" value="Submit" />
</form>
<%
dim fname
fname=Request.Form("fname")
If fname<>"" Then
Response.Write("Hello " & fname & "!<br />")
Response.Write("How are you today?")
End If
%>
</body>
</html>
29.
<html>
<%
dim cars
cars=Request.Form("cars")
%>
<body>
<form action="demo_radiob.asp" method="post">
<p>Please select your favorite car:</p>
<input type="radio" name="cars"
<%if cars="Volvo" then Response.Write("checked")%>
value="Volvo">Volvo</input>
<br />
<input type="radio" name="cars"
<%if cars="Saab" then Response.Write("checked")%>
value="Saab">Saab</input>
<br />
<input type="radio" name="cars"
<%if cars="BMW" then Response.Write("checked")%>
value="BMW">BMW</input>
<br /><br />
<input type="submit" value="Submit" />
</form>
<%
if cars<>"" then
Response.Write("<p>Your favorite car is: " & cars & "</p>")

end if
%>
</body>
</html>
30.
<%
dim numvisits
response.cookies("NumVisits").Expires=date+365
numvisits=request.cookies("NumVisits")
if numvisits="" then
response.cookies("NumVisits")=1
response.write("Welcome! This is the first time you are visiting this Web page.")
else
response.cookies("NumVisits")=numvisits+1
response.write("You have visited this ")
response.write("Web page " & numvisits)
if numvisits=1 then
response.write " time before!"
else
response.write " times before!"
end if
end if
%>
<html>
<body>
</body>
</html>
31.
<html>
<body>
<%
response.write("Hello World!")
%>
</body>
</html>
32.
<html>
<body>
<%
response.write("<h2>You can use HTML tags to format the text!</h2>")
%>
<%
response.write("<p style='color:#0000ff'>This text is styled with the style attribute!
</p>")
%>

</body>
</html>
33.
<%
if Request.Form("select")<>"" then
Response.Redirect(Request.Form("select"))
end if
%>
<html>
<body>
<form action="demo_redirect.asp" method="post">
<input type="radio" name="select"
value="demo_server.asp">
Server Example<br>
<input type="radio" name="select"
value="demo_text.asp">
Text Example<br><br>
<input type="submit" value="Go!">
</form>
</body>
</html>
34.
<html>
<body>
<%
randomize()
r=rnd()
if r>0.5 then
response.write("<a href='http://www.w3schools.com'>W3Schools.com!</a>")
else
response.write("<a href='http://www.refsnesdata.no'>Refsnesdata.no!</a>")
end if
%>
<p>
This example demonstrates a link, each time you load the page, it will display
one of two links: W3Schools.com! OR Refsnesdata.no! There is a 50% chance for
each of them.
</p>
</body>
</html>

35.
<%
Response.Buffer=true
%>
<html>
<body>
<p>
This text will be sent to your browser when my response buffer is flushed.
</p>
<%
Response.Flush
%>
</body>
</html>
36.
<%
Response.Buffer=true
%>
<html>
<body>
<p>This is some text I want to send to the user.</p>
<p>No, I changed my mind. I want to clear the text.</p>
<%
Response.Clear
%>
</body>
</html>
37.
<html>
<body>
<p>I am writing some text. This text will never be<br>
<%
Response.End
%>
finished! It's too late to write more!</p>
</body>
</html>
38.
<%Response.Expires=-1%>
<html>
<body>
<p>This page will be refreshed with each access!</p>
</body>
</html>

39.
<%
Response.ExpiresAbsolute=#May 05,2001 05:30:30#
%>
<html>
<body>
<p>This page will expire on May 05, 2001 05:30:30!</p>
</body>
</html>
40.
<html>
<body>
<%
If Response.IsClientConnected=true then
Response.Write("The user is still connected!")
else
Response.Write("The user is not connected!")
end if
%>
</body>
</html>
41.
<%
Response.ContentType="text/html"
%>
<html>
<body>
<p>This is some text</p>
</body>
</html>
42.
<%
Response.Charset="ISO8859-1"
%>
<html>
<body>
<p>This is some text</p>
</body>
</html>

43.
<html>
<body>
<a href="demo_simplequerystring.asp?color=green">Example</a>
<%
Response.Write(Request.QueryString)
%>
</body>
</html>
44.
<html>
<body>
<form action="demo_simplereqquery.asp" method="get">
First name: <input type="text" name="fname"><br>
Last name: <input type="text" name="lname"><br>
<input type="submit" value="Submit">
</form>
<%
Response.Write(Request.QueryString)
%>
</body>
</html>
45.
<html>
<body>
<form action="demo_reqquery.asp" method="get">
Your name: <input type="text" name="fname" size="20" />
<input type="submit" value="Submit" />
</form>
<%
dim fname
fname=Request.QueryString("fname")
If fname<>"" Then
Response.Write("Hello " & fname & "!<br />")
Response.Write("How are you today?")
End If
%>
</body>
</html>
46.
<html>
<body>
<%

If Request.QueryString<>"" Then
If Request.QueryString("name")<>", " Then
name1=Request.QueryString("name")(1)
name2=Request.QueryString("name")(2)
end if
end if
%>
<form action="demo_reqquery2.asp" method="get">
First name:
<input type="text" name="name" value="<%=name1%>" />
<br />
Last name:
<input type="text" name="name" value="<%=name2%>" />
<br />
<input type="submit" value="Submit" />
</form>
<hr>
<%
If Request.QueryString<>"" Then
Response.Write("<p>")
Response.Write("The information received from the form was:")
Response.Write("</p><p>")
Response.Write("name=" & Request.QueryString("name"))
Response.Write("</p><p>")
Response.Write("The name property's count is: ")
Response.Write(Request.QueryString("name").Count)
Response.Write("</p><p>")
Response.Write("First name=" & name1)
Response.Write("</p><p>")
Response.Write("Last name=" & name2)
Response.Write("</p>")
end if
%>
</body>
</html>
47.
<html>
<body>
<form action="demo_simpleform1.asp" method="post">
First name:
<input type="text" name="fname" value="Donald" />
<br />
Last name:
<input type="text" name="lname" value="Duck" />
<br />
<input type="submit" value="Submit" />
</form>
<%
Response.Write(Request.Form)

%>
</body>
</html>
48.
<html>
<body>
<form action="demo_simpleform.asp" method="post">
Your name: <input type="text" name="fname" size="20" />
<input type="submit" value="Submit" />
</form>
<%
dim fname
fname=Request.Form("fname")
If fname<>"" Then
Response.Write("Hello " & fname & "!<br />")
Response.Write("How are you today?")
End If
%>
</body>
</html>
49.
<html>
<body>
<form action="demo_form2.asp" method="post">
First name:
<input type="text" name="name" value="Donald" />
<br />
Last name:
<input type="text" name="name" value="Duck" />
<br />
<input type="submit" value="Submit" />
</form>
<hr />
<p>The information received from the form above was:</p>
<%
If Request.Form("name")<>"" Then
Response.Write("<p>")
Response.Write("name=" & Request.Form("name"))
Response.Write("</p><p>")
Response.Write("The name property's count is: ")
Response.Write(Request.Form("name").Count)
Response.Write("</p><p>")
Response.Write("First name=" & Request.Form("name")(1))
Response.Write("</p><p>")
Response.Write("Last name=" & Request.Form("name")(2))
Response.Write("</p>")
End if
%>

</body>
</html>
49.
<html>
<%
dim cars
cars=Request.Form("cars")
%>
<body>
<form action="demo_radiob.asp" method="post">
<p>Please select your favorite car:</p>
<input type="radio" name="cars"
<%if cars="Volvo" then Response.Write("checked")%>
value="Volvo">Volvo</input>
<br />
<input type="radio" name="cars"
<%if cars="Saab" then Response.Write("checked")%>
value="Saab">Saab</input>
<br />
<input type="radio" name="cars"
<%if cars="BMW" then Response.Write("checked")%>
value="BMW">BMW</input>
<br /><br />
<input type="submit" value="Submit" />
</form>
<%
if cars<>"" then
Response.Write("<p>Your favorite car is: " & cars & "</p>")
end if
%>
</body>
</html>
50.
<html>
<body>
<%
fruits=Request.Form("fruits")
%>
<form action="demo_checkboxes.asp" method="post">
<p>Which of these fruits do you prefer:</p>
<input type="checkbox" name="fruits" value="Apples"
<%if instr(fruits,"Apple") then Response.Write("checked")%>>
Apple
<br>
<input type="checkbox" name="fruits" value="Oranges"
<%if instr(fruits,"Oranges") then Response.Write("checked")%>>
Orange
<br>

<input type="checkbox" name="fruits" value="Bananas"


<%if instr(fruits,"Banana") then Response.Write("checked")%>>
Banana
<br>
<input type="submit" value="Submit">
</form>
<%
if fruits<>"" then%>
<p>You like: <%Response.Write(fruits)%></p>
<%end if
%>
</body>
</html>
51.
<html>
<body>
<p>
<b>You are browsing this site with:</b>
<%Response.Write(Request.ServerVariables("http_user_agent"))%>
</p>
<p>
<b>Your IP address is:</b>
<%Response.Write(Request.ServerVariables("remote_addr"))%>
</p>
<p>
<b>The DNS lookup of the IP address is:</b>
<%Response.Write(Request.ServerVariables("remote_host"))%>
</p>
<p>
<b>The method used to call the page:</b>
<%Response.Write(Request.ServerVariables("request_method"))%>
</p>
<p>
<b>The server's domain name:</b>
<%Response.Write(Request.ServerVariables("server_name"))%>
</p>
<p>
<b>The server's port:</b>
<%Response.Write(Request.ServerVariables("server_port"))%>
</p>
<p>
<b>The server's software:</b>
<%Response.Write(Request.ServerVariables("server_software"))%>
</p>
</body>
</html>

52.
<html>
<body>
<p>
All possible server variables:
</p>
<%
For Each Item in Request.ServerVariables
Response.Write(Item & "<br />")
Next
%>
</body>
</html>
53.
<%
dim numvisits
response.cookies("NumVisits").Expires=date+365
numvisits=request.cookies("NumVisits")
if numvisits="" then
response.cookies("NumVisits")=1
response.write("Welcome! This is the first time you are visiting this Web page.")
else
response.cookies("NumVisits")=numvisits+1
response.write("You have visited this ")
response.write("Web page " & numvisits)
if numvisits=1 then
response.write " time before!"
else
response.write " times before!"
end if
end if
%>
<html>
<body>
</body>
</html>
54.
<html>
<body>
<form action="demo_totalbytes.asp" method="post">
Please type something:
<input type="text" name="txt"><br><br>

<input type="submit" value="Submit">


</form>
<%
If Request.Form("txt")<>"" Then
Response.Write("You submitted: ")
Response.Write(Request.Form)
Response.Write("<br><br>")
Response.Write("Total bytes: ")
Response.Write(Request.Totalbytes)
End If
%>
</body>
</html>
55.
<html>
<body>
<%
Response.Write(Session.SessionID)
%>
</body>
</html>
56.
<html>
<body>
<%
response.write("<p>")
response.write("Default Timeout is: " & Session.Timeout & " minutes.")
response.write("</p>")
Session.Timeout=30
response.write("<p>")
response.write("Timeout is now: " & Session.Timeout & " minutes.")
response.write("</p>")
%>
</body>
</html>
57.
<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>
58.
<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>
59.
<%
Set FS=Server.CreateObject("Scripting.FileSystemObject")
Set RS=FS.OpenTextFile(Server.MapPath("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>
This page has been visited <%=fcount%> times.
</p>

</body>
</html>
60.
<html>
<body>
<%
Set fs=Server.CreateObject("Scripting.FileSystemObject")
If (fs.FileExists("c:\winnt\cursors\3dgarro.cur"))=true Then
Response.Write("File c:\winnt\cursors\3dgarro.cur exists.")
Else
Response.Write("File c:\winnt\cursors\3dgarro.cur does not exist.")
End If
set fs=nothing
%>
</body>
</html>
61.
<html>
<body>
<%
Set fs=Server.CreateObject("Scripting.FileSystemObject")
If fs.FolderExists("c:\temp") = true Then
Response.Write("Folder c:\temp exists.")
Else
Response.Write("Folder c:\temp does not exist.")
End If
set fs=nothing
%>
</body>
</html>
62.
<html>
<body>
<%
Set fs=Server.CreateObject("Scripting.FileSystemObject")
if fs.driveexists("c:") = true then
Response.Write("Drive c: exists.")
Else
Response.Write("Drive c: does not exist.")
End If
Response.write("<br>")

if fs.driveexists("g:") = true then


Response.Write("Drive g: exists.")
Else
Response.Write("Drive g: does not exist.")
End If
set fs=nothing
%>
</body>
</html>
63.
<html>
<body>
<%
Set fs=Server.CreateObject("Scripting.FileSystemObject")
p=fs.GetDriveName("c:\winnt\cursors\3dgarro.cur")
Response.Write("The drive name is: " & p)
set fs=nothing
%>
</body>
</html>
64.
<html>
<body>
<%
Set fs=Server.CreateObject("Scripting.FileSystemObject")
p=fs.GetParentFolderName("c:\winnt\cursors\3dgarro.cur")
Response.Write("The parent folder name of c:\winnt\cursors\3dgarro.cur is: " & p)
set fs=nothing
%>
</body>
</html>
65.
<html>
<body>
<%
Set fs=Server.CreateObject("Scripting.FileSystemObject")
Response.Write("The file extension of the file 3dgarro is: ")

Response.Write(fs.GetExtensionName("c:\winnt\cursors\3dgarro.cur"))
set fs=nothing
%>
</body>
</html>
66.
<html>
<body>
<%
Set fs=Server.CreateObject("Scripting.FileSystemObject")
Response.Write(fs.GetBaseName("c:\winnt\cursors\3dgarro.cur"))
Response.Write("<br />")
Response.Write(fs.GetBaseName("c:\winnt\cursors\"))
Response.Write("<br />")
Response.Write(fs.GetBaseName("c:\winnt\"))
set fs=nothing
%>
</body>
</html>
67.
<html>
<body>
<p>This is the text in the text file:</p>
<%
Set fs=Server.CreateObject("Scripting.FileSystemObject")
Set f=fs.OpenTextFile(Server.MapPath("testread.txt"), 1)
Response.Write(f.ReadAll)
f.Close
Set f=Nothing
Set fs=Nothing
%>
</body>
</html>
68.
<html>
<body>
<p>This is the first five characters from the text file:</p>
<%
Set fs=Server.CreateObject("Scripting.FileSystemObject")
Set f=fs.OpenTextFile(Server.MapPath("testread.txt"), 1)

Response.Write(f.Read(5))
f.Close
Set f=Nothing
Set fs=Nothing
%>
</body>
</html>
69.
<html>
<body>
<p>This is the first line of the text file:</p>
<%
Set fs=Server.CreateObject("Scripting.FileSystemObject")
Set f=fs.OpenTextFile(Server.MapPath("testread.txt"), 1)
Response.Write(f.ReadLine)
f.Close
Set f=Nothing
Set fs=Nothing
%>
</body>
</html>
70.
<html>
<body>
<p>This is all the lines in the text file:</p>
<%
Set fs=Server.CreateObject("Scripting.FileSystemObject")
Set f=fs.OpenTextFile(Server.MapPath("testread.txt"), 1)
do while f.AtEndOfStream = false
Response.Write(f.ReadLine)
Response.Write("<br>")
loop
f.Close
Set f=Nothing
Set fs=Nothing
%>
</body>
</html>

71.
<html>
<body>
<p>The first four characters in the text file are skipped:</p>
<%
Set fs=Server.CreateObject("Scripting.FileSystemObject")
Set f=fs.OpenTextFile(Server.MapPath("testread.txt"), 1)
f.Skip(4)
Response.Write(f.ReadAll)
f.Close
Set f=Nothing
Set fs=Nothing
%>
</body>
</html>
72.
<html>
<body>
<p>The first line in the text file is skipped:</p>
<%
Set fs=Server.CreateObject("Scripting.FileSystemObject")
Set f=fs.OpenTextFile(Server.MapPath("testread.txt"), 1)
f.SkipLine
Response.Write(f.ReadAll)
f.Close
Set f=Nothing
Set fs=Nothing
%>
</body>
</html>
73.
<html>
<body>
<p>This is all the lines in the text file (with line numbers):</p>
<%
Set fs=Server.CreateObject("Scripting.FileSystemObject")
Set f=fs.OpenTextFile(Server.MapPath("testread.txt"), 1)
do while f.AtEndOfStream = false
Response.Write("Line:" & f.Line & " ")
Response.Write(f.ReadLine)
Response.Write("<br>")

loop
f.Close
Set f=Nothing
Set fs=Nothing
%>
</body>
</html>
74.
<html>
<body>
<%
Set fs=Server.CreateObject("Scripting.FileSystemObject")
Set f=fs.OpenTextFile(Server.MapPath("testread.txt"), 1)
Response.Write(f.Read(2))
Response.Write("<p>The cursor is now standing in position " & f.Column & " in the
text file.</p>")
f.Close
Set f=Nothing
Set fs=Nothing
%>
</body>
</html>
75.
<html>
<body>
<%
Dim fs, d, n
Set fs=Server.CreateObject("Scripting.FileSystemObject")
Set d=fs.GetDrive("c:")
n = "Drive: " & d
n = n & "<br>Available Space in bytes: " & d.AvailableSpace
Response.Write(n)
set d=nothing
set fs=nothing
%>
</body>
</html>
76.
<html>
<body>
<%

Dim fs, d, n
Set fs=Server.CreateObject("Scripting.FileSystemObject")
Set d=fs.GetDrive("c:")
n = "Drive: " & d
n = n & "<br />Free Space in bytes: " & d.FreeSpace
Response.Write(n)
set d=nothing
set fs=nothing
%>
</body>
</html>
77.
<html>
<body>
<%
Dim fs,d,n
Set fs=Server.CreateObject("Scripting.FileSystemObject")
Set d=fs.GetDrive("c:")
n = "Drive: " & d
n = n & "<br>Total size in bytes: " & d.TotalSize
Response.Write(n)
set d=nothing
set fs=nothing
%>
</body>
</html>
78.
<html>
<body>
<%
dim fs, d, n
set fs=Server.CreateObject("Scripting.FileSystemObject")
set d=fs.GetDrive("c:")
Response.Write("The drive letter is: " & d.driveletter)
set d=nothing
set fs=nothing
%>
</body>
</html>

79.
<html>
<body>
<%
dim fs, d, n
set fs=Server.CreateObject("Scripting.FileSystemObject")
set d=fs.GetDrive("c:")
Response.Write("The drive type is: " & d.DriveType)
set d=nothing
set fs=nothing
%>
</body>
</html>
80.
<html>
<body>
<%
dim fs, d, n
set fs=Server.CreateObject("Scripting.FileSystemObject")
set d=fs.GetDrive("c:")
Response.Write("The file system is: " & d.FileSystem)
set d=nothing
set fs=nothing
%>
</body>
</html>
81.
<html>
<body>
<%
dim fs,d,n
set fs=Server.CreateObject("Scripting.FileSystemObject")
set d=fs.GetDrive("c:")
n = "The " & d.DriveLetter
if d.IsReady=true then
n = n & " drive is ready."
else
n = n & " drive is not ready."
end if
Response.Write(n)
set d=nothing
set fs=nothing
%>
</body>
</html>

82.
<html>
<body>
<%
dim fs,d
set fs=Server.CreateObject("Scripting.FileSystemObject")
set d=fs.GetDrive("c:")
Response.Write("The path is " & d.Path)
set d=nothing
set fs=nothing
%>
</body>
</html>
83.
<html>
<body>
<%
dim fs,d
set fs=Server.CreateObject("Scripting.FileSystemObject")
set d=fs.GetDrive("c:")
Response.Write("The rootfolder is " & d.RootFolder)
set d=nothing
set fs=nothing
%>
</body>
</html>
84.
<html>
<body>
<%
dim fs,d
set fs=Server.CreateObject("Scripting.FileSystemObject")
set d=fs.GetDrive("c:")
Response.Write("The serialnumber is " & d.SerialNumber)
set d=nothing
set fs=nothing
%>
</body>
</html>

85.
<html>
<body>
<%
dim fs, f
set fs=Server.CreateObject("Scripting.FileSystemObject")
set f=fs.GetFile(Server.MapPath("testread.txt"))
Response.Write("The file testread.txt was created on: " & f.DateCreated)
set f=nothing
set fs=nothing
%>
</body>
</html>
86.
<html>
<body>
<%
dim fs, f
set fs=Server.CreateObject("Scripting.FileSystemObject")
set f=fs.GetFile(Server.MapPath("testread.txt"))
Response.Write("The file testread.txt was last modified on: " & f.DateLastModified)
set f=nothing
set fs=nothing
%>
</body>
</html>
87.
<html>
<body>
<%
dim fs, f
set fs=Server.CreateObject("Scripting.FileSystemObject")
set f=fs.GetFile(Server.MapPath("testread.txt"))
Response.Write("The file testread.txt was last accessed on: " & f.DateLastAccessed)
set f=nothing
set fs=nothing
%>
</body>
</html>

88.
<html>
<body>
<%
dim fs,f
set fs=Server.CreateObject("Scripting.FileSystemObject")
set f=fs.GetFile(Server.MapPath("testread.txt"))
Response.Write("The attributes of the file testread.txt are: " & f.Attributes)
set f=nothing
set fs=nothing
%>
</body>
</html>
89.
<body>
<%
dim d
set d=Server.CreateObject("Scripting.Dictionary")
d.Add "n", "Norway"
d.Add "i", "Italy"
if d.Exists("n")= true then
Response.Write("Key exists.")
else
Response.Write("Key does not exist.")
end if
set d=nothing
%>
</body>
</html>
90.
<html>
<body>
<%
dim d,a,i,s
set d=Server.CreateObject("Scripting.Dictionary")
d.Add "n", "Norway"
d.Add "i", "Italy"
Response.Write("<p>The values of the items are:</p>")
a=d.Items
for i = 0 To d.Count -1
s = s & a(i) & "<br>"
next
Response.Write(s)
set d=nothing

%>
</body>
</html>
91.
<html>
<body>
<%
dim d,a,i,s
set d=Server.CreateObject("Scripting.Dictionary")
d.Add "n", "Norway"
d.Add "i", "Italy"
Response.Write("<p>The value of the keys are:</p>")
a=d.Keys
for i = 0 To d.Count -1
s = s & a(i) & "<br>"
next
Response.Write(s)
set d=nothing
%>
</body>
</html>
92.
<html>
<body>
<%
dim d
set d=Server.CreateObject("Scripting.Dictionary")
d.Add "n", "Norway"
d.Add "i", "Italy"
Response.Write("The value of the item n is: " & d.item("n"))
set d=nothing
%>
</body>
</html>
93.
<html>
<body>
<%
dim d
set d=Server.CreateObject("Scripting.Dictionary")
d.Add "n", "Norway"
d.Add "i", "Italy"
d.Key("i") = "it"
Response.Write("The key i has been set to it, and the value is: " & d.Item("it"))

set d=nothing
%>
</body>
</html>
94.
<html>
<body>
<%
dim d, a, s, i
set d=Server.CreateObject("Scripting.Dictionary")
d.Add "n", "Norway"
d.Add "i", "Italy"
Response.Write("The number of key/item pairs is: " & d.Count)
set d=nothing
%>
</body>
</html>
95.
<html>
<body>
<%
set adrotator=Server.CreateObject("MSWC.AdRotator")
adrotator.Border="2"
Response.Write(adrotator.GetAdvertisement("text/advertisements.txt"))
%>
<p>
NOTE: Because images are changed randomly, and because this page has few
images to choose from, it will often display the same advertisement twice in a row.
</p>
<p>
<a href="text/advertisements.txt">
<img border="0" src="/images/btn_view_text.gif">
</a>
</p>
</body>
</html>
96.
<%
url=Request.QueryString("url")
If url<>"" then Response.Redirect(url)
%>
<html>
<body>

<%
set adrotator=Server.CreateObject("MSWC.AdRotator")
adrotator.TargetFrame="target='_blank'"
response.write(adrotator.GetAdvertisement("text/advertisements2.txt"))
%>
<p>
NOTE: Because images are changed randomly, and because this page has few
images to choose from, it will
often display the same advertisement twice in a row.
</p>
<p>
<a href="text/advertisements2.txt">
<img border="0" src="/images/btn_view_text.gif"></a>
</p>
</body>
</html>
97.
<html>
<body>
<%
Set MyBrow=Server.CreateObject("MSWC.BrowserType")
%>
<table border="1" width="65%">
<tr>
<td width="52%">Client OS</td>
<td width="48%"><%=MyBrow.platform%></td>
</tr>
<tr>
<td >Web Browser</td>
<td ><%=MyBrow.browser%></td>
</tr>
<tr>
<td>Browser version</td>
<td><%=MyBrow.version%></td>
</tr>
<tr>
<td>Frame support?</td>
<td><%=MyBrow.frames%></td>
</tr>
<tr>
<td>Table support?</td>
<td><%=MyBrow.tables%></td>
</tr>
<tr>
<td>Sound support?</td>
<td><%=MyBrow.backgroundsounds%></td>
</tr>

<tr>
<td>Cookies support?</td>
<td><%=MyBrow.cookies%></td>
</tr>
<tr>
<td>VBScript support?</td>
<td><%=MyBrow.vbscript%></td>
</tr>
<tr>
<td>JavaScript support?</td>
<td><%=MyBrow.javascript%></td>
</tr>
</table>
</body>
</html>
98.
<html>
<body>
<p><b>Note:</b> This example won't work because ASP 3.0 is not installed on our
server.
</p>
<p>
<a href="demo_textads.asp"><img border="0"
src="/images/btn_view_text.gif"></a>
</p>
<%
set cr=server.createobject("MSWC.ContentRotator")
response.write(cr.ChooseContent("text/textads.txt"))
%>
<p>
NOTE: Because the content strings are changed randomly in the text file, and this
page has only four content strings to choose from, sometimes the page will display
the same content strings twice in a row.
</p>
</body>
</html>
99.
<html>
<body>
<p>
The example below builds a table of contents.
</p>
<%

dim c
dim i
set nl=server.createobject("MSWC.Nextlink")
c = nl.GetListCount("text\links.txt")
i=1
%>
<ul>
<%do while (i <= c) %>
<li><a href="<%=nl.GetNthURL("text\links.txt", i)%>">
<%=nl.GetNthDescription("text\links.txt", i)%></a>
<%
i = (i + 1)
loop
%>
</ul>
<p>
The text file contains a list of page urls
and link descriptions. It contains one line of text for each page. Note that the url and
description MUST be separated by the TAB character.
</p>
<p>
<a href="text/links.txt"><img border="0" src="/images/btn_view_text.gif"></a>
</p>
</body>
</html>
100.
<html>
<body>
<h1>
This is page 1!
</h1>
<%
Set nl=Server.CreateObject("MSWC.NextLink")
If (nl.GetListIndex("text/links2.txt")>1) Then
%>
<a href="<%Response.Write(nl.GetPreviousURL("text/links2.txt"))%>">Previous
Page</a>
<%End If%>
<a href="<%Response.Write(nl.GetNextURL("text/links2.txt"))%>">Next Page</a>
<p>The example uses the Content Linking Component
to navigate between the pages in a text file.</p>
<p>
<a href="text/links2.txt"><img border="0" src="/images/btn_view_text.gif"></a>
</p>
</body>
</html>

Vous aimerez peut-être aussi