亚洲国产日韩欧美一区二区三区,精品亚洲国产成人av在线,国产99视频精品免视看7,99国产精品久久久久久久成人热,欧美日韩亚洲国产综合乱

annuaire recherche
ASP 基礎教程 在自己的 PC 上運行 ASP ASP 基本語法規(guī)則 ASP 變量 ASP 子程序 ASP 表單和用戶輸入 ASP Cookies ASP Session 對象 ASP Application 對象 ASP 引用文件 ASP Global.asa 文件 ASP 使用 CDOSYS 發(fā)送電子郵件 ASP 對象 ASP Response 對象 ASP Cookies 集合 ASP Buffer 屬性 ASP CacheControl 屬性 ASP Charset 屬性 ASP ContentType 屬性 ASP Expires 屬性 ASP ExpiresAbsolute 屬性 ASP IsClientConnected 屬性 ASP PICS 屬性 ASP Status 屬性 ASP AddHeader 方法 ASP AppendToLog 方法 ASP BinaryWrite 方法 ASP Clear 方法 ASP End 方法 ASP Flush 方法 ASP Redirect 方法 ASP Write 方法 ASP Request 對象 ASP Cookies 集合 ASP Form 集合 ASP QueryString 集合 ASP ServerVariables 集合 ASP 教程 ASP TotalBytes 屬性 ASP BinaryRead 方法 ASP Application 對象 ASP Contents 集合 ASP StaticObjects 集合 ASP Contents.RemoveAll 方法 ASP Lock 和 Unlock 方法 ASP Application OnStart 和 Application OnEnd 事件 ASP Session 對象 ASP Contents 集合 ASP StaticObjects 集合 ASP CodePage 屬性 ASP LCID 屬性 ASP SessionID 屬性 ASP Timeout 屬性 ASP Abandon 方法 ASP Contents.Remove 方法 ASP Contents.RemoveAll 方法 ASP Session OnStart 和 Session OnEnd 事件 ASP ScriptTimeout 屬性 ASP CreateObject 方法 ASP Execute 方法 ASP Server 對象 ASP GetLastError() 方法 (ASP 3.0) ASP HTMLEncode 方法 ASP MapPath 方法 ASP Transfer 方法 ASP URLEncode 方法 ASP ASPError 對象 ASP ASPError 對象的屬性 ASP FileSystemObject 對象 ASP Drives 屬性 ASP BuildPath 方法 ASP CopyFile 方法 ASP CopyFolder 方法 ASP CreateFolder 方法 ASP CreateTextFile 方法 ASP DeleteFile 方法 ASP DeleteFolder 方法 ASP DriveExists 方法 ASP FileExists 方法 ASP FolderExists 方法 ASP GetAbsolutePathName 方法 ASP GetBaseName 方法 ASP GetDrive 方法 ASP GetDriveName 方法 ASP GetExtensionName 方法 ASP GetFile 方法 ASP GetFileName 方法 ASP GetFolder 方法 ASP GetParentFolderName 方法 ASP GetSpecialFolder 方法 ASP GetTempName 方法 ASP MoveFile 方法 ASP MoveFolder 方法 ASP OpenTextFile 方法 ASP TextStream 對象 ASP AtEndOfLine 屬性 ASP AtEndOfStream 屬性 ASP Column 屬性 ASP Line 屬性 ASP Close 方法 ASP Read 方法 ASP ReadAll 方法 ASP ReadLine 方法 ASP Skip 方法 ASP SkipLine 方法 ASP Write 方法 ASP WriteLine 方法 ASP WriteBlankLines 方法 ASP Drive 對象 ASP AvailableSpace 屬性 ASP DriveLetter 屬性 ASP DriveType 屬性 ASP FileSystem 屬性 ASP FreeSpace 屬性 ASP IsReady 屬性 ASP Path 屬性 ASP RootFolder 屬性 ASP SerialNumber 屬性 ASP ShareName 屬性 ASP TotalSize 屬性 ASP VolumeName 屬性 ASP File 對象 ASP Attributes 屬性 ASP DateCreated 屬性 ASP DateLastAccessed 屬性 ASP DateLastModified 屬性 ASP Drive 屬性 ASP Name 屬性 ASP ParentFolder 屬性 ASP Path 屬性 ASP ShortName 屬性 ASP ShortPath 屬性 ASP Size 屬性 ASP Type 屬性 ASP Copy 方法 ASP Delete 方法 ASP Move 方法 ASP OpenAsTextStream 方法 ASP Folder 對象 ASP Files 集合 ASP SubFolders 集合 ASP Attributes 屬性 ASP DateCreated 屬性 ASP DateLastAccessed 屬性 ASP DateLastModified 屬性 ASP Drive 屬性 ASP IsRootFolder 屬性 ASP Name 屬性 ASP ParentFolder 屬性 ASP Path 屬性 ASP ShortName 屬性 ASP ShortPath 屬性 ASP Size 屬性 ASP Type 屬性 ASP Copy 方法 ASP Delete 方法 ASP Move 方法 ASP CreateTextFile 方法 ASP Dictionary 對象 ASP CompareMode 屬性 ASP Count 屬性 ASP Item 屬性 ASP Key 屬性 ASP Add 方法 ASP Exists 方法 ASP Items 方法 ASP Keys 方法 ASP Remove 方法 ASP RemoveAll 方法 ASP ADO ASP 組件 ASP AdRotator 組件 ASP Browser Capabilities 組件 ASP Content Linking 組件 ASP Content Rotator 組件 (ASP 3.0) ASP 與 AJAX AJAX 簡介 ASP - AJAX 與 ASP AJAX 數據庫實例 ASP 實例 ASP 實例 ASP 快速參考
personnages

ASP 實例


基礎

用ASP寫文本

<!DOCTYPE?html>
<html>
<body>

<%
response.write("Hello?World!")
%>

</body>
</html>

向文本添加HTML

<!DOCTYPE?html>
<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>

變量

聲明變量
變量用于存儲信息。本例演示如何聲明變量,為變量賦值,并在程序中使用這個變量。

<!DOCTYPE?html>
<html>
<body>

<%
dim?name
name="Donald?Duck"
response.write("My?name?is:?"?&?name)
%>

</body>
</html>
My?name?is:?Donald?Duck

聲明數組
數組用于存儲一系列相關的數據項目。本例演示如何聲明一個存儲名字的數組。

<!DOCTYPE?html>
<html>
<body>

<%
Dim?famname(5),i
famname(0)?=?"Jan?Egil"
famname(1)?=?"Tove"
famname(2)?=?"Hege"
famname(3)?=?"Stale"
famname(4)?=?"Kai?Jim"
famname(5)?=?"Borge"

For?i?=?0?to?5
??????response.write(famname(i)?&?"<br>")
Next
%>

</body>
</html>
Jan?Egil
Tove
Hege
Stale
Kai?Jim
Borge

循環(huán)生成 HTML 標題
本例演示如何循環(huán)生成 6 個不同的 HTML 標題。

<!DOCTYPE?html>
<html>
<body>

<%
dim?i?
for?i=1?to?6
???response.write("<h"?&?i?&?">Heading?"?&?i?&?"</h"?&?i?&?">")
next
%>

</body>
</html>

Heading 1

Heading 2

Heading 3

Heading 4

Heading 5
Heading 6

使用 Vbscript 制作基于時間的問候語
本例演示如何根據服務器時間向用戶顯示不同的消息。

<!DOCTYPE?html>
<html>
<body>
<%
dim?h
h=hour(now())

response.write("<p>"?&?now())
response.write("</p>")
If?h<12?then
???response.write("Good?Morning!")
else
???response.write("Good?day!")
end?if
%>
</body>
</html>
9/20/2013?11:08:35?PM
Good?day!

使用 JavaScript 制作基于時間的問候語
本例同上,演示如何根據服務器時間向用戶顯示不同的消息,只是語法不同而已。

<%@?language="javascript"?%>
<!DOCTYPE?html>
<html>
<body>
<%
var?d=new?Date()
var?h=d.getHours()

Response.Write("<p>")
Response.Write(d)
Response.Write("</p>")
if?(h<12)
???{
???Response.Write("Good?Morning!")
???}
else
???{
???Response.Write("Good?day!")
???}
%>
</body>
</html>
Fri?Sep?20?23:08:38?EDT?2013
Good?day!


Date/Time 函數(VBScript)

日期和時間

<!DOCTYPE?html>
<html>
<body>

Today's?date?is:?<%response.write(date())%>.
<br>
The?server's?local?time?is:?<%response.write(time())%>.

</body>
</html>

獲得天的名字

<!DOCTYPE?html>
<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>

獲得月的名字

<!DOCTYPE?html>
<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>

獲得今天的月和天

<!DOCTYPE?html>
<html>
<body>

Today?it?is
<%response.write(WeekdayName(weekday(date)))%>,
<br>
and?the?month?is
<%response.write(MonthName(month(date)))%>

</body>
</html>

3000年倒計時

<!DOCTYPE?html>
<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>

從今天起計算N天后

<!DOCTYPE?html>
<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>

格式化日期和時間

<!DOCTYPE?html>
<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>

這是一個日期嗎?

<!DOCTYPE?html>
<html>
<body>

<%
somedate="10/30/99"
response.write(IsDate(somedate))
%>

</body>
</html>

其他函數(VBScript)

大寫或小寫的字符串

<!DOCTYPE?html>
<html>
<body>

<%
name?=?"Bill?Gates"
response.write(ucase(name))
response.write("<br>")
response.write(lcase(name))
%>

</body>
</html>

字符串去掉前后空格

<!DOCTYPE?html>
<html>
<body>

<%
name?=?"?jianzhan?"
response.write("visit"?&?name?&?"now<br>")
response.write("visit"?&?trim(name)?&?"now<br>")
response.write("visit"?&?ltrim(name)?&?"now<br>")
response.write("visit"?&?rtrim(name)?&?"now")
%>

</body>
</html>

如何轉化一個字符串?

<!DOCTYPE?html>
<html>
<body>

<%
sometext?=?"Hello?Everyone!"
response.write(strReverse(sometext))
%>

</body>
</html>

四舍五入

<!DOCTYPE?html>
<html>
<body>

<%
i?=?48.66776677
j?=?48.3333333
response.write(Round(i))
response.write("<br>")
response.write(Round(j))
%>

</body>
</html>

一個隨機數

<!DOCTYPE?html>
<html>
<body>

<%
randomize()
response.write(rnd())
%>

</body>
</html>

從一個字符串返回特定的字符

<!DOCTYPE?html>
<html>
<body>

<%
sometext="Welcome?to?this?Web"
response.write(Left(sometext,5))
response.write("<br>")
response.write(Right(sometext,5))
%>

</body>
</html>

替換字符串的特定字符

<!DOCTYPE?html>
<html>
<body>

<%
sometext="Welcome?to?this?Web!!"
response.write(Replace(sometext,?"Web",?"Page"))
%>

</body>
</html>

從字符串中返回指定數目的字符

<!DOCTYPE?html>
<html>
<body>

<%
sometext="Welcome?to?this?Web!!"
response.write(Mid(sometext,?9,?2))
%>

</body>
</html>

程序

調用使用VBScript的子程序

<!DOCTYPE?html>
<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>

調用使用JavaScript的子程序

<%@?language="javascript"?%>
<!DOCTYPE?html>
<html>
<head>
<%
function?jsproc(num1,num2)
{
Response.Write(num1*num2)
}
%>
</head>

<body>
<p>Result:?<%jsproc(3,4)%></p>
</body>
</html>

調用使用VBScript和JavaScript的子程序

<!DOCTYPE?html>
<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>

表單

使用method="get"的表單

<!DOCTYPE?html>
<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>

使用method="post"的表單

<!DOCTYPE?html>
<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>

使用單選按鈕的表單

<!DOCTYPE?html>
<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>

Cookie

Welcome cookie

<%
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
%>
<!DOCTYPE?html>
<html>
<body>
</body>
</html>

Response 對象

使用 ASP 寫文本
本例演示如何使用 ASP 來寫文本。

<!DOCTYPE?html>
<html>
<body>

<%
response.write("Hello?World!")
%>

</body>
</html>
Hello?World!

在 ASP 中使用 HTML 標簽格式化文本
本例演示如何使用 ASP 將文本和 HTML 標簽結合起來。

<!DOCTYPE?html>
<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>

You can use HTML tags to format the text!

This text is styled with the style attribute!

將用戶重定向至一個不同的 URL
本例演示如何將用戶重定向至一個不同的 URL。

<%
if?Request.Form("select")<>""?then
???????Response.Redirect(Request.Form("select"))
end?if
%>???

<!DOCTYPE?html>
<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>

顯示隨機的鏈接
本例演示如何創(chuàng)建一個隨機的鏈接。

<!DOCTYPE?html>
<html>
<body>

<%
randomize()
r=rnd()
if?r>0.5?then
??response.write("<a?)
else
??response.write("<a?)
end?if
%>

<p>
This?example?demonstrates?a?link,?each?time?you?load?the?page,?it?will?display?
one?of?two?links:?jianzhan.cc!?OR?Refsnesdata.no!?There?is?a?50%?chance?for?
each?of?them.
</p>

</body>
</html>

控制緩沖區(qū)
本例演示如何控制緩沖區(qū)。

<%
Response.Buffer=true
%>
<!DOCTYPE?html>
<html>
<body>
<p>
This?text?will?be?sent?to?your?browser?when?my?response?buffer?is?flushed.
</p>
<%
Response.Flush
%>
</body>
</html>

清空緩沖區(qū)
本例演示如何清空緩沖區(qū)。

<%
Response.Buffer=true
%>
<!DOCTYPE?html>
<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>

在處理過程中終止腳本并返回結果
本例演示如何在處理過程中終止腳本。

<!DOCTYPE?html>
<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>

設置頁面在失效前在瀏覽器中緩存時間
本例演示如何規(guī)定頁面在失效前在瀏覽器中的緩存時間。

<%Response.Expires=-1%>
<!DOCTYPE?html>
<html>
<body>
<p>This?page?will?be?refreshed?with?each?access!</p>
</body>
</html>

設置頁面緩存在瀏覽器中的失效日期或時間
本例演示如何規(guī)定頁面緩存在瀏覽器中的失效時間日期或時間。

<%Response.Expires=-1%>
<!DOCTYPE?html>
<html>
<body>
<p>This?page?will?be?refreshed?with?each?access!</p>
</body>
</html>

檢查用戶是否仍然與服務器連接
本例演示如何檢查用戶是否已與服務器斷開。

<!DOCTYPE?html>
<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>

設置內容類型
本例演示如何規(guī)定內容的類型。

<%
Response.ContentType="text/html"
%>
<!DOCTYPE?html>
<html>
<body>

<p>This?is?some?text</p>

</body>
</html>

設置字符集名稱
本例演示如何規(guī)定字符集的名稱。

<%
Response.Charset="ISO8859-1"
%>
<!DOCTYPE?html>
<html>
<body>

<p>This?is?some?text</p>

</body>
</html>

Request 對象

當用戶點擊鏈接時發(fā)送查詢信息
本例演示如何在鏈接中向頁面發(fā)送查詢信息,并在目標頁面中取回這些信息(在本例中是同一頁面)。

<!DOCTYPE?html>
<html>
<body>

<a?href="demo_simplequerystring.asp?color=green">Example</a>

<%
Response.Write(Request.QueryString)
%>

</body>
</html>

QueryString 集合的簡單應用
本例演示如何使用 QueryString 集合從表單取回值。(此表單使用 GET 方法,這意味著所發(fā)送的信息對用戶來說是可見的。)

<!DOCTYPE?html>
<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>

如何使用來自表單的信息
本例演示如何使用從表單取回的值。此表單使用 GET 方法。

<!DOCTYPE?html>
<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>

來自表單的更多信息
本例演示如果輸入字段包含若干相同的名稱,QueryString 集合會包含什么內容。它將展示如何使用 Count 關鍵詞來對 "name" 屬性進行計數。此表單使用 GET 方法。

<!DOCTYPE?html>
<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>

在線實例

Form 集合的簡單應用
本例演示如何使用 Form 集合從表單取回值。(此表單使用 POST 方法,這意味著所發(fā)送的信息對用戶來說是不可見的。)

<!DOCTYPE?html>
<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>

如何使用來自表單的信息
本例演示如何使用從表單取回的值。此表單使用了 POST 方法。

<!DOCTYPE?html>
<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>

來自表單的更多信息
本例演示如果輸入字段包含若干相同的名稱,F(xiàn)orm 集合會包含什么內容。它將展示如何使用 Count 關鍵詞來對 "name" 屬性進行計數。此表單使用了 POST 方法。

<!DOCTYPE?html>
<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>

帶有單選按鈕的表單
本例演示如何使用 Form 集合通過單選按鈕與用戶進行交互。此表單使用 POST 方法。

<!DOCTYPE?html>
<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>

帶有復選框的表單
本例演示如何使用 Form 集合通過復選框與用戶進行交互。此表單使用 POST 方法。

<!DOCTYPE?html>
<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>

在線實例

獲取服務器變量
本例演示如何取得訪客的瀏覽器類型、IP 地址等信息。

<!DOCTYPE?html>
<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>
You?are?browsing?this?site?with:
Your?IP?address?is:?42.120.45.233
The?DNS?lookup?of?the?IP?address?is:?42.120.45.233
The?method?used?to?call?the?page:?GET
The?server's?domain?name:?shouce.ren
The?server's?port:?80
The?server's?software:?Microsoft-IIS/7.5

創(chuàng)建 welcome cookie
本例演示如何創(chuàng)建一個 Welcome Cookie。

<%
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
%>
<!DOCTYPE?html>
<html>
<body>
</body>
</html>

探測用戶發(fā)送的字節(jié)總數
本例演示如何探測用戶在 Request 對象中發(fā)送的字節(jié)總數。

<!DOCTYPE?html>
<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>

Session 對象

設置并返回 LCID
本例演示 "LCID" 屬性。該屬性設置并返回一個指示位置或者地區(qū)的整數。類似于日期、時間和貨幣等內容都要根據位置或者地區(qū)來顯示。

<!DOCTYPE?html>
<html>
<body>

<%??
response.write("<p>")
response.write("The?default?LCID?for?this?page?is:?"?&?Session.LCID?&?"<br>")
response.write("The?Date?format?for?the?above?LCID?is:?"?&?date()?&?"<br>")
response.write("The?Currency?format?for?the?above?LCID?is:?"?&?FormatCurrency(350))
response.write("</p>")

Session.LCID=1036

response.write("<p>")
response.write("The?LCID?is?now?changed?to:?"?&?Session.LCID?&?"<br>")
response.write("The?Date?format?for?the?above?LCID?is:?"?&?date()?&?"<br>")
response.write("The?Currency?format?for?the?above?LCID?is:?"?&?FormatCurrency(350))
response.write("</p>")

Session.LCID?=?3079

response.write("<p>")
response.write("The?LCID?is?now?changed?to:?"?&?Session.LCID?&?"<br>")
response.write("The?Date?format?for?the?above?LCID?is:?"?&?date()?&?"<br>")
response.write("The?Currency?format?for?the?above?LCID?is:?"?&?FormatCurrency(350))
response.write("</p>")

Session.LCID?=?2057

response.write("<p>")
response.write("The?LCID?is?now?changed?to:?"?&?Session.LCID?&?"<br>")
response.write("The?Date?format?for?the?above?LCID?is:?"?&?date()?&?"<br>")
response.write("The?Currency?format?for?the?above?LCID?is:?"?&?FormatCurrency(350))
response.write("</p>")
%>

</body>
</html>
The?default?LCID?for?this?page?is:?1033
The?Date?format?for?the?above?LCID?is:?9/20/2013
The?Currency?format?for?the?above?LCID?is:?$350.00
The?LCID?is?now?changed?to:?1036
The?Date?format?for?the?above?LCID?is:?20/09/2013
The?Currency?format?for?the?above?LCID?is:?350,00??
The?LCID?is?now?changed?to:?3079
The?Date?format?for?the?above?LCID?is:?20.09.2013
The?Currency?format?for?the?above?LCID?is:???350,00
The?LCID?is?now?changed?to:?2057
The?Date?format?for?the?above?LCID?is:?20/09/2013
The?Currency?format?for?the?above?LCID?is:?£350.00

返回 SessionID
本例演示 "SessionID" 屬性。該屬性為每位用戶返回一個唯一的 id。這個 id 由服務器生成。

<!DOCTYPE?html>
<html>
<body>

<%
Response.Write(Session.SessionID)
%>

</body>
</html>
619100248

session 的超時
本例演示 "Timeout" 屬性。該屬性設置并返回 session 的超時時間(分鐘)。

<!DOCTYPE?html>
<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>
Default?Timeout?is:?20?minutes.
Timeout?is?now:?30?minutes.

Server 對象

此文件最后被修改的時間是?
探測文件的最后修改時間。

<!DOCTYPE?html>
<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>

打開并讀取某個文本文件
打開文件 "Textfile.txt" 以供讀取。

<!DOCTYPE?html>
<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?src="/images/btn_view_text.gif"></a>
</p>

</body>
</html>

自制的點擊計數器

<%
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

%>
<!DOCTYPE?html>
<html>
<body>
<p>
This?page?has?been?visited?<%=fcount%>??times.
</p>
</body>
</html>

FileSystem 對象

指定的文件存在嗎?
本例演示如何檢查某個文件是否存在。

<!DOCTYPE?html>
<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>

指定的文件夾存在嗎?
本例演示如何檢查某個文件夾是否存在。

<!DOCTYPE?html>
<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>

指定的驅動器存在嗎?
本例演示如何檢查某個驅動器是否存在。

<!DOCTYPE?html>
<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>

取得某個指定驅動器的名稱
本例演示如何獲取某個指定的驅動器的名稱。

<!DOCTYPE?html>
<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>

取得某個指定路徑的父文件夾的名稱
本例演示如何獲取某個指定的路徑的父文件夾的名稱。

<!DOCTYPE?html>
<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>

取得文件名
本例演示如何獲取指定的路徑中的最后一個成分的文件名。

<!DOCTYPE?html>
<html>
<body>

<%
Set?fs=Server.CreateObject("Scripting.FileSystemObject")

Response.Write("The?file?name?of?the?last?component?is:?")
Response.Write(fs.GetFileName("c:\winnt\cursors\3dgarro.cur"))
set?fs=nothing
%>


</body>
</html>

取得文件擴展名
本例演示如何獲取指定的路徑中的最后一個成分的文件擴展名。

<!DOCTYPE?html>
<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>

取得文件或文件夾的基名稱
本例演示如何獲取指定的路徑中文件或者文件夾的基名稱。

<!DOCTYPE?html>
<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>

TextStream 對象

讀取文本文件
本例演示如何從文本文件中讀取內容。

<!DOCTYPE?html>
<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>

讀取文本文件中的一個部分
本例演示如何僅僅讀取一個文本流文件的部分內容。

<!DOCTYPE?html>
<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>

讀取文本文件中的一行
本例演示如何從一個文本流文件中讀取一行內容。

<!DOCTYPE?html>
<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>

讀取文本文件的所有行
本例演示如何從文本流文件中讀取所有的行。

<!DOCTYPE?html>
<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>

略過文本文件中的一部分
本例演示如何在讀取文本流文件時跳過指定的字符數。

<!DOCTYPE?html>
<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>

略過文本文件中的一行
本例演示如何在讀取文本流文件時跳過一行。

<!DOCTYPE?html>
<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>

返回行數
本例演示如何返回在文本流文件中的當前行號。

<!DOCTYPE?html>
<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>

取得列數
本例演示如何取得在文件中當前字符的列號。

<!DOCTYPE?html>
<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>

Drive 對象

取得指定驅動器的總容量
本例演示如何使用 TotalSize 屬性來獲得指定驅動器的總容量。

<!DOCTYPE?html>
<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>

取得指定驅動器的可用空間數
本例演示如何首先創(chuàng)建一個 FileSystemObject 對象,然后使用 AvailableSpace 屬性來獲得指定驅動器的可用空間。

<!DOCTYPE?html>
<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>

取得指定驅動器的剩余空間容量
本例演示如何使用 FreeSpace 空間屬性來取得指定驅動器的剩余空間。

<!DOCTYPE?html>
<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>

取得指定驅動器的驅動器字母
本例演示如何使用 DriveLetter 屬性來獲得指定驅動器的驅動器字母。

<!DOCTYPE?html>
<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>

取得指定驅動器的驅動器類型
本例演示如何使用 DriveType 屬性來獲得指定驅動器的驅動器類型。

<!DOCTYPE?html>
<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>

取得指定驅動器的文件系統(tǒng)信息
本例演示如何使用 FileSystem 來取得指定驅動器的文件系統(tǒng)信息。

<!DOCTYPE?html>
<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>

驅動器是否已就緒?
本例演示如何使用 IsReady 屬性來檢查指定的驅動器是否已就緒。

<!DOCTYPE?html>
<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>

取得指定驅動器的路徑
本例演示如何使用 Path 屬性來取得指定驅動器的路徑。

<!DOCTYPE?html>
<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>

取得指定驅動器的根文件夾
本例演示如何使用 RootFolder 屬性來取得指定驅動器的根文件夾。

<!DOCTYPE?html>
<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>

取得指定驅動器的序列號
本例演示如何使用 Serialnumber 屬性來取得指定驅動器的序列號。

<!DOCTYPE?html>
<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>

File 對象

文件最后被修改的時間?
本例演示如何使用 DateLastModified 屬性來取得指定文件最后被修改的日期和時間。

<!DOCTYPE?html>
<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>

文件最后被訪問的時間?
此例演示如何使用 DateLastAccessed 屬性來取得指定文件最后被訪問的日期和時間。

<!DOCTYPE?html>
<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>

返回指定文件的屬性
本例演示如何使用 Attributes 來返回指定文件的屬性。

<!DOCTYPE?html>
<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>

Dictionary 對象

指定的鍵存在嗎?
本例演示如何創(chuàng)建一個 Dictionary 對象,然后使用 Exists 方法來檢查指定的鍵是否存在。

<!DOCTYPE?html>
<html>
<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>

返回一個所有項目的數組
本例演示如何使用 Items 方法來返回一個所有項目的數組。

<!DOCTYPE?html>
<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>

返回一個所有鍵的數組
本例演示如何使用 Keys 方法來返回一個所有鍵的數組。

<!DOCTYPE?html>
<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>

返回一個項目的值
本例演示如何使用 Item 屬性來返回一個項目的值。

<!DOCTYPE?html>
<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>

設置一個鍵
本例演示如何使用 Key 屬性來在 Dictionary 對象中設置一個鍵。

<!DOCTYPE?html>
<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>

返回鍵/項目對的數量
本例演示如何使用 Count 屬性來返回鍵/項目對的數量。

<!DOCTYPE?html>
<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>

Article précédent: Article suivant: