Date post: | 06-Jan-2016 |
Category: |
Documents |
Upload: | hocvien-daotao |
View: | 221 times |
Download: | 0 times |
7/17/2019 ASP Object
http://slidepdf.com/reader/full/asp-object-568c48fd9cde8 1/22
ASP Object
ASP Response Object
The ASP Response object is used to send output to the user from the server.
Examples
Write text with ASP
This example demonstrates how to write text with ASP.
Format text with HT! ta"s in ASPThis example demonstrates how to combine text and HT! ta"s with ASP.
Redirect the user to a different #R!
This example demonstrates how to redirect the user to a different #R!.
Show a random lin$
This example demonstrates a lin$% each time &ou load the pa"e% it will displa& one of
two lin$s' W(Schools.com) *R Refsnesdata.no) There is a +,- chance for each of
them.
ontrollin" the buffer This example demonstrates how &ou can control the buffer.
lear the buffer
This example demonstrates how &ou can clear the buffer.
/nd a script in the middle of processin" and return the result
This example demonstrates how to end a script in the middle of processin".
Set how man& minutes a pa"e will be cached in a browser before it expires
This example demonstrates how to specif& how man& minutes a pa"e will be cached
in a browser before it expires.
Set a date0time when a pa"e cached in a browser will expire
This example demonstrates how to specif& a date0time a pa"e cached in a browser will
expire.
hec$ if the user is still connected to the server
This example demonstrates how to chec$ if a user is disconnected from the server.
Set the t&pe of content
This example demonstrates how to specif& the t&pe of content.
7/17/2019 ASP Object
http://slidepdf.com/reader/full/asp-object-568c48fd9cde8 2/22
Set the name of the character set
This example demonstrates how to specif& the name of the character set.
Response Object
The ASP Response object is used to send output to the user from the server. 1ts
collections% properties% and methods are described below'
Collections
Collection Description
oo$ies Sets a coo$ie value. 1f the coo$ie does not exist% it will be
created% and ta$e the value that is specified
Properties
Property Description
2uffer Specifies whether to buffer the pa"e output or not
acheontrol Sets whether a prox& server can cache the output "enerated b&
ASP or not
harset Appends the name of a character3set to the content3t&pe header
in the Response object
ontentT&pe Sets the HTTP content t&pe for the Response object
/xpires Sets how lon" 4in minutes5 a pa"e will be cached on a browser
before it expires
/xpiresAbsolute Sets a date and time when a pa"e cached on a browser will
expire
1slientonnected 1ndicates if the client has disconnected from the server
Pics Appends a value to the P1S label response header
Status Specifies the value of the status line returned b& the server
Methods
Method Description
AddHeader Adds a new HTTP header and a value to the HTTP response
AppendTo!o" Adds a strin" to the end of the server lo" entr&
2inar&Write Writes data directl& to the output without an& character
conversion
lear lears an& buffered HT! output
/nd Stops processin" a script% and returns the current result
7/17/2019 ASP Object
http://slidepdf.com/reader/full/asp-object-568c48fd9cde8 3/22
Flush Sends buffered HT! output immediatel&
Redirect Redirects the user to a different #R!
Write Writes a specified strin" to the output
ASP Request Object
The ASP Re6uest object is used to "et information from the user.
QueryString Collection Examples
Send 6uer& information when a user clic$s on a lin$ This example demonstrates how to send some extra 6uer& information to a pa"e
within a lin$% and retrieve that information on the destination pa"e 4which is% in this
example% the same pa"e5.
A 7uer&Strin" collection in its simplest use
This example demonstrates how the QueryString collection retrieves the values from
a form. The form uses the 8/T method% which means that the information sent is
visible to ever&bod& 4in the address field5. The 8/T method also limits the amount of
information that can be sent.
How to use information from forms
This example demonstrates how to use the values retrieved from a form. We use the
QueryString collection. The form uses the "et method.
ore information from a form
This example demonstrates what the QueryString contains if several input fields
have the same name. 1t shows how to separate input fields with e6ual names from
each other. 1t also shows how to use the Count $e&word to count the 9name9 propert&.
The form uses the "et method.
Form Collection Examples
A form collection in its simplest use
This example demonstrates how the Form collection retrieves the values from a form.
The form uses the P*ST method% which means that the information sent is invisible to
others% and it has no limits 4&ou can send a lar"e amount of information5.
How to use information from forms
This example demonstrates how to use the values retrieved from a form. We use the
Form collection. The form uses the post method.
ore information from a formThis example demonstrates what the Form collection contains if several input fields
7/17/2019 ASP Object
http://slidepdf.com/reader/full/asp-object-568c48fd9cde8 4/22
have the same name. 1t shows how to separate input fields with e6ual names from
each other. 1t also shows how to use the Count $e&word to count the 9name9 propert&.
The form uses the post method.
A form with radio buttons
This example demonstrates how to interact with the user throu"h radio buttons% withthe Form collection. The form uses the post method.
A form with chec$boxes
This example demonstrates how to interact with the user throu"h chec$boxes% with
the Form collection. The form uses the post method.
Other Examples
8et the server variables
This example demonstrates how to find out the visitors 4&ours5 browser t&pe% 1P
address% and more with the Server!ri!bles collection.
reate a welcome coo$ie
This example demonstrates how to create a Welcome oo$ie with the Coo"ies
ollection.
Find the total number of b&tes the user sent
This example demonstrates how to use the #ot!l$ytes propert& to find out the total
number of b&tes the user sent in the Re6uest object.
Request Object
When a browser as$s for a pa"e from a server% it is called a re6uest. The ASP Re6uest
object is used to "et information from the user. 1ts collections% properties% and methods
are described below'
Collections
Collection Description
lientertificate ontains all the field values stored in the client certificate
oo$ies ontains all the coo$ie values sent in a HTTP re6uest
Form ontains all the form 4input5 values from a form that uses the
post method
7uer&Strin" ontains all the variable values in a HTTP 6uer& strin"
Server:ariables ontains all the server variable values
Properties
Property Description
7/17/2019 ASP Object
http://slidepdf.com/reader/full/asp-object-568c48fd9cde8 5/22
Total2&tes Returns the total number of b&tes the client sent in the bod& of
the re6uest
Methods
Method Description
2inar&Read Retrieves the data sent to the server from the client as part of a
post re6uest and stores it in a safe arra&
ASP Applic!tion Object
A "roup of ASP files that wor$ to"ether to perform some purpose is called an
application. The Application object in ASP is used to tie these files to"ether.
Application Object
An application on the Web ma& be a "roup of ASP files. The ASP files wor$ to"ether
to perform some purpose. The Application object in ASP is used to tie these files
to"ether.
The Application object is used to store and access variables from an& pa"e% just li$e
the Session object. The difference is that A!! users share one Application object%while with Sessions there is one Session object for /AH user.
The Application object should hold information that will be used b& man& pa"es in
the application 4li$e database connection information5. This means that &ou can
access the information from an& pa"e. 1t also means that &ou can chan"e the
information in one place and the chan"es will automaticall& be reflected on all pa"es.
The Application object;s collections% methods% and events are described below'
Collections
Collection Description
ontents ontains all the items appended to the application throu"h a
script command
Static*bjects ontains all the objects appended to the application with the
HT! <object= ta"
Methods
Method Description
ontents.Remove >eletes an item from the ontents collection
7/17/2019 ASP Object
http://slidepdf.com/reader/full/asp-object-568c48fd9cde8 6/22
ontents.RemoveAll45 >eletes all items from the ontents collection
!oc$ Prevents other users from modif&in" the variables in the
Application object
#nloc$ /nables other users to modif& the variables in the
Application object 4after it has been loc$ed usin" the !oc$
method5
Events
%vent Description
Application?*n/nd *ccurs when all user sessions are over% and the application
ends
Application?*nStart *ccurs before the first new session is created 4when the
Application object is first referenced5
ASP Session Object
The Session object is used to store information about% or chan"e settin"s for a user
session. :ariables stored in the Session object hold information about one sin"le user%
and are available to all pa"es in one application.
Examples
Set and return the !1>
This example demonstrates the 9!1>9 propert&. This propert& sets or returns an
inte"er that specifies a location or re"ion. ontents li$e date% time% and currenc& will
be displa&ed accordin" to that location or re"ion.
Return the Session1>
This example demonstrates the 9Session1>9 propert&. This propert& returns a uni6ue
id for each user. The id is "enerated b& the server.
A session;s timeout
This example demonstrates the 9Timeout9 propert&. This example sets and returns the
timeout 4in minutes5 for the session.
Session Object
When &ou are wor$in" with an application% &ou open it% do some chan"es and then
&ou close it. This is much li$e a Session. The computer $nows who &ou are. 1t $nowswhen &ou start the application and when &ou end. 2ut on the internet there is one
7/17/2019 ASP Object
http://slidepdf.com/reader/full/asp-object-568c48fd9cde8 7/22
problem' the web server does not $now who &ou are and what &ou do because the
HTTP address doesn;t maintain state.
ASP solves this problem b& creatin" a uni6ue coo$ie for each user. The coo$ie is sent
to the client and it contains information that identifies the user. This interface is called
the Session object.
The Session object is used to store information about% or chan"e settin"s for a user
session. :ariables stored in the Session object hold information about one sin"le user%
and are available to all pa"es in one application. ommon information stored in
session variables are name% id% and preferences. The server creates a new Session
object for each new user% and destro&s the Session object when the session expires.
The Session object;s collections% properties% methods% and events are described below'
Collections
Collection Description
ontents ontains all the items appended to the session throu"h a
script command
Static*bjects ontains all the objects appended to the session with the
HT! <object= ta"
Properties
Property Description
odePa"e Specifies the character set that will be used when
displa&in" d&namic content
!1> Sets or returns an inte"er that specifies a location or
re"ion. ontents li$e date% time% and currenc& will be
displa&ed accordin" to that location or re"ion
Session1> Returns a uni6ue id for each user. The uni6ue id is
"enerated b& the server
Timeout Sets or returns the timeout period 4in minutes5 for the
Session object in this application
Methods
Method Description
Abandon >estro&s a user session
ontents.Remove >eletes an item from the ontents collection
ontents.RemoveAll45 >eletes all items from the ontents collection
7/17/2019 ASP Object
http://slidepdf.com/reader/full/asp-object-568c48fd9cde8 8/22
Events
%vent Description
Session?*n/nd *ccurs when a session ends
Session?*nStart *ccurs when a session starts
ASP Server Object
The ASP Server object is used to access properties and methods on the server.
Examples
When was a file last modified@
hec$s when this file was last modified.
*pen a text file for readin"
This example opens the file 9Textfile.txt9 for readin".
Homemade hit counter
This example reads a number from a file% adds to the number% and writes the number
bac$ to the file.
Server Object
The ASP Server object is used to access properties and methods on the server. 1ts
properties and methods are described below'
Properties
Property Description
ScriptTimeout Sets or returns the maximum number of seconds a script can run before it is terminated
Methods
Method Description
reate*bject reates an instance of an object
/xecute /xecutes an ASP file from inside another ASP file
8et!ast/rror45 Returns an ASP/rror object that describes the error condition
that occurred
7/17/2019 ASP Object
http://slidepdf.com/reader/full/asp-object-568c48fd9cde8 9/22
HT!/ncode Applies HT! encodin" to a specified strin"
apPath aps a specified path to a ph&sical path
Transfer Sends 4transfers5 all the information created in one ASP file to a
second ASP file
#R!/ncode Applies #R! encodin" rules to a specified strin"
ASP%rror Object &ASP '()*
The ASP/rror object is used to displa& detailed information of an& error that occurs in
scripts in an ASP pa"e.
The ASError Object
The ASP/rror object is implemented in ASP (., and it is onl& available in 11S+.
The ASP /rror object is used to displa& detailed information of an& error that occurs
in scripts in an ASP pa"e. The ASP/rror object is created when Server.8et!ast/rror is
called% so the error information can onl& be accessed b& usin" the Server.8et!ast/rror
method.
The ASP/rror object;s properties are described below 4all properties are read3onl&5'
+ote, The properties below can onl& be accessed throu"h the Server.8et!ast/rror45
method.
Properties
Property Description
ASPode Returns an error code "enerated b& 11S
ASP>escription Returns a detailed description of the error 4if the error is ASP3
related5
ate"or& Returns the source of the error 4was the error "enerated b& ASP@
2& a scriptin" lan"ua"e@ 2& an object@5
olumn Returns the column position within the file that "enerated the
error
>escription Returns a short description of the error
File Returns the name of the ASP file that "enerated the error
!ine Returns the line number where the error was detected
Bumber Returns the standard * error code for the error
7/17/2019 ASP Object
http://slidepdf.com/reader/full/asp-object-568c48fd9cde8 10/22
Source
Returns the actual source code of the line where the error
occurred
ASP FileSystemObject Object
The FileS&stem*bject object is used to access the file s&stem on the server.
Examples
>oes a specified file exist@
This example demonstrates how to first create a FileS&stem*bject *bject% and thenuse the File/xists method to chec$ if the file exists.
>oes a specified folder exist@
This example demonstrates how to use the Folder/xists method to chec$ if a folder
exists.
>oes a specified drive exist@
This example demonstrates how to use the >rive/xists method to chec$ if a drive
exists.
8et the name of a specified drive
This example demonstrates how to use the 8et>riveBame method to "et the name of
a specified drive.
8et the name of the parent folder of a specified path
This example demonstrates how to use the 8etParentFolderBame method to "et the
name of the parent folder of a specified path.
8et the file extension
This example demonstrates how to use the 8et/xtensionBame method to "et the file
extension of the last component in a specified path.
8et file name
This example demonstrates how to use the 8etFileBame method to "et the file name
of the last component in a specified path.
8et the base name of a file or folder
This example demonstrates how to use the 8et2aseBame method to return the base
name of the file or folder% in a specified path.
7/17/2019 ASP Object
http://slidepdf.com/reader/full/asp-object-568c48fd9cde8 11/22
The FileSystemObject Object
The FileS&stem*bject object is used to access the file s&stem on the server. This
object can manipulate files% folders% and director& paths. 1t is also possible to retrieve
file s&stem information with this object.
The followin" code creates a text file 4c'Ctest.txt5 and then writes some text to the file'
<-
dim fs%fname
set fsDServer.reate*bject49Scriptin".FileS&stem*bject95
set fnameDfs.reateTextFile49c'Ctest.txt9%true5
fname.Write!ine49Hello World)95
fname.lose
set fnameDnothin"
set fsDnothin"-=
The FileS&stem*bject object;s properties and methods are described below'
Properties
Property Description
>rives Returns a collection of all >rive objects on the computer
MethodsMethod Description
2uildPath Appends a name to an existin" path
op&File opies one or more files from one location to another
op&Folder opies one or more folders from one location to another
reateFolder reates a new folder
reateTextFile reates a text file and returns a TextStream object that can
be used to read from% or write to the file
>eleteFile >eletes one or more specified files
>eleteFolder >eletes one or more specified folders
>rive/xists hec$s if a specified drive exists
File/xists hec$s if a specified file exists
Folder/xists hec$s if a specified folder exists
8etAbsolutePathBame Returns the complete path from the root of the drive for
the specified path
8et2aseBame Returns the base name of a specified file or folder
7/17/2019 ASP Object
http://slidepdf.com/reader/full/asp-object-568c48fd9cde8 12/22
8et>rive Returns a >rive object correspondin" to the drive in a
specified path
8et>riveBame Returns the drive name of a specified path
8et/xtensionBame Returns the file extension name for the last component in
a specified path
8etFile Returns a File object for a specified path
8etFileBame Returns the file name or folder name for the last
component in a specified path
8etFolder Returns a Folder object for a specified path
8etParentFolderBame Returns the name of the parent folder of the last
component in a specified path
8etSpecialFolder Returns the path to some of Windows; special folders
8etTempBame Returns a randoml& "enerated temporar& file or folder
oveFile oves one or more files from one location to another
oveFolder oves one or more folders from one location to another
*penTextFile *pens a file and returns a TextStream object that can be
used to access the file
ASP #e-tStre!m ObjectThe TextStream object is used to access the contents of a text file.
Examples
Read textfile
This example demonstrates how to use the *penTextFile method of the
FileS&stem*bject to create a TextStream *bject. The ReadAll method of the
TextStream *bject reads from the opened text file.
Read onl& a part of a textfile
This example demonstrates how to onl& read a part of a TextStream file.
Read one line of a textfile
This example demonstrates how to read one line from a TextStream file.
Read all lines from a textfile
This example demonstrates how to read all the lines from a TextStream file.
7/17/2019 ASP Object
http://slidepdf.com/reader/full/asp-object-568c48fd9cde8 13/22
S$ip a part of a textfile
This example demonstrates how to s$ip a specified number of characters when
readin" the TextStream file.
S$ip a line of a textfile
This example demonstrates how to s$ip a line when readin" the TextStream file.
Return line3number
This example demonstrates how to return the current line number in a TextStream file.
8et column number
This example demonstrates how to "et the column number of the current character in
a file.
The TextStream Object
The TextStream object is used to access the contents of text files.
The followin" code creates a text file 4c'Ctest.txt5 and then writes some text to the file
4the variable f is an instance of the TextStream object5'
<%
dim fs, f
set fs=Server.CreateObject("Scripting.FileSystemObject")
set f=fs.Createe!tFile("c#test.t!t",tr$e)
f.rite&ine("'ell rld")f.Clse
set f=nt*ing
set fs=nt*ing
%+
To create an instance of the TextStream object &ou can use the reateTextFile or
*penTextFile methods of the FileS&stem*bject object% or &ou can use the
*penAsTextStream method of the File object.
The TextStream object;s properties and methods are described below'
Properties
Property Description
At/nd*f!ine Returns true if the file pointer is positioned immediatel& before
the end3of3line mar$er in a TextStream file% and false if not
At/nd*fStream Returns true if the file pointer is at the end of a TextStream file%
and false if not
olumn Returns the column number of the current character position in
an input stream
7/17/2019 ASP Object
http://slidepdf.com/reader/full/asp-object-568c48fd9cde8 14/22
!ine Returns the current line number in a TextStream file
Methods
Method Description
lose loses an open TextStream file
Read Reads a specified number of characters from a TextStream file
and returns the result
ReadAll Reads an entire TextStream file and returns the result
Read!ine Reads one line from a TextStream file and returns the result
S$ip S$ips a specified number of characters when readin" a
TextStream file
S$ip!ine S$ips the next line when readin" a TextStream file
Write Writes a specified text to a TextStream file
Write!ine Writes a specified text and a new3line character to a TextStream
file
Write2lan$!ines Writes a specified number of new3line character to a TextStream
file
ASP Drive ObjectThe >rive object is used to return information about a local dis$ drive or a networ$
share.
Examples
8et the available space of a specified drive
This example demonstrates how to first create a FileS&stem*bject object% and then
use the AvailableSpace propert& to "et the available space of a specified drive.
8et the free space of a specified drive
This example demonstrates how to use the FreeSpace propert& to "et the free space of
a specified drive.
8et the total siEe of a specified drive
This example demonstrates how to use the TotalSiEe propert& to "et the total siEe of a
specified drive.
7/17/2019 ASP Object
http://slidepdf.com/reader/full/asp-object-568c48fd9cde8 15/22
8et the drive letter of a specified drive
This example demonstrates how to use the >rive!etter propert& to "et the drive letter
of a specified drive.
8et the drive t&pe of a specified drive
This example demonstrates how to use the >riveT&pe propert& to "et the drive t&pe of a specified drive.
8et the file s&stem of a specified drive
This example demonstrates how to use the FileS&stem propert& to "et the file s&stem
of a specified drive.
1s the drive read&@
This example demonstrates how to use the 1sRead& propert& to chec$ whether a
specified drive is read&.
8et the path of a specified driveThis example demonstrates how to use the Path propert& to "et the path of a specified
drive.
8et the root folder of a specified drive
This example demonstrates how to use the RootFolder propert& to "et the root folder
of a specified drive.
8et the serialnumber of a specified drive
This example demonstrates how to use the Serialnumber propert& to "et the
serialnumber of a specified drive.
The !rive Object
The >rive object is used to return information about a local dis$ drive or a networ$
share. The >rive object can return information about a drive;s t&pe of file s&stem% free
space% serial number% volume name% and more.
+ote, ou cannot return information about a drive;s content with the >rive object. For
this purpose &ou will have to use the Folder object.
To wor$ with the properties of the >rive object% &ou will have to create an instance of
the >rive object throu"h the FileS&stem*bject object. FirstG create a
FileS&stem*bject object and then instantiate the >rive object throu"h the 8et>rive
method or the >rives propert& of the FileS&stem*bject object.
The followin" example uses the 8et>rive method of the FileS&stem*bject object to
instantiate the >rive object and the TotalSiEe propert& to return the total siEe in b&tes
of the specified drive 4c'5'
<%
7/17/2019 ASP Object
http://slidepdf.com/reader/full/asp-object-568c48fd9cde8 16/22
im fs,d
Set fs=Server.CreateObject("Scripting.FileSystemObject")
Set d=fs.-etrive("c")
espnse.rite("rive " / d / "")
espnse.rite("tal si0e in bytes " / d.talSi0e)
set d=nt*ing
set fs=nt*ing%+
*utput'
>rive c' Total siEe in b&tes' IJ(+K((JI
The >rive object;s properties are described below'
Properties
Property Description
AvailableSpace Returns the amount of available space to a user on a specified
drive or networ$ share
>rive!etter Returns one uppercase letter that identifies the local drive or a
networ$ share
>riveT&pe Returns the t&pe of a specified drive
FileS&stem Returns the file s&stem in use for a specified drive
FreeSpace Returns the amount of free space to a user on a specified drive or
networ$ share
1sRead& Returns true if the specified drive is read& and false if not
Path Returns an uppercase letter followed b& a colon that indicates
the path name for a specified drive
RootFolder Returns a Folder object that represents the root folder of a
specified drive
SerialBumber Returns the serial number of a specified drive
ShareBame Returns the networ$ share name for a specified drive
TotalSiEe Returns the total siEe of a specified drive or networ$ share
:olumeBame Sets or returns the volume name of a specified drive
ASP File Object
The File object is used to return information about a specified file.
7/17/2019 ASP Object
http://slidepdf.com/reader/full/asp-object-568c48fd9cde8 17/22
Examples
When was the file created@
This example demonstrates how to first create a FileS&stem*bject object% and then
use the >atereated propert& of the File object to "et the date and time a specified file
was created.
When was the file last modified@
This example demonstrates how to use the >ate!astodified propert& to "et the date
and time a specified file was last modified.
When was the file last accessed@
This example demonstrates how to use the >ate!astAccessed propert& to "et the date
and time a specified file was last accessed.
Return the attributes of a specified file
This example demonstrates how to use the Attributes propert& to return the attributes
of a specified file.
The File Object
The File object is used to return information about a specified file.
To wor$ with the properties and methods of the File object% &ou will have to create an
instance of the File object throu"h the FileS&stem*bject object. FirstG create aFileS&stem*bject object and then instantiate the File object throu"h the 8etFile
method of the FileS&stem*bject object or throu"h the Files propert& of the Folder
object.
The followin" code uses the 8etFile method of the FileS&stem*bject object to
instantiate the File object and the >atereated propert& to return the date when the
specified file was created'
<%
im fs,f
Set fs=Server.CreateObject("Scripting.FileSystemObject")Set f=fs.-etFile("c#test.t!t")
espnse.rite("File created " / f.ateCreated)
set f=nt*ing
set fs=nt*ing
%+
*utput'
File created 123124553 355331 67
The File object;s properties and methods are described below'
7/17/2019 ASP Object
http://slidepdf.com/reader/full/asp-object-568c48fd9cde8 18/22
Properties
Property Description
Attributes Sets or returns the attributes of a specified file
>atereated Returns the date and time when a specified file was created>ate!astAccessed Returns the date and time when a specified file was last
accessed
>ate!astodified Returns the date and time when a specified file was last
modified
>rive Returns the drive letter of the drive where a specified file or
folder resides
Bame Sets or returns the name of a specified file
ParentFolder Returns the folder object for the parent of the specified filePath Returns the path for a specified file
ShortBame Returns the short name of a specified file 4the L.( namin"
convention5
ShortPath Returns the short path of a specified file 4the L.( namin"
convention5
SiEe Returns the siEe% in b&tes% of a specified file
T&pe Returns the t&pe of a specified file
Methods
Method Description
op& opies a specified file from one location to another
>elete >eletes a specified file
ove oves a specified file from one location to another
*penAsTextStream *pens a specified file and returns a TextStream object to
access the file
ASP Folder Object
The Folder *bject is used to return information about a specified folder.
The Fol"er Object
The Folder object is used to return information about a specified folder.
7/17/2019 ASP Object
http://slidepdf.com/reader/full/asp-object-568c48fd9cde8 19/22
To wor$ with the properties and methods of the Folder object% &ou will have to create
an instance of the Folder object throu"h the FileS&stem*bject object. FirstG create a
FileS&stem*bject object and then instantiate the Folder object throu"h the 8etFolder
method of the FileS&stem*bject object.
The followin" code uses the 8etFolder method of the FileS&stem*bject object toinstantiate the Folder object and the >atereated propert& to return the date when the
specified folder was created'
<%
im fs,f
Set fs=Server.CreateObject("Scripting.FileSystemObject")
Set f=fs.-etFlder("c#test")
espnse.rite("Flder created " / f.ateCreated)
set f=nt*ing
set fs=nt*ing
%+
*utput'
Flder created 3524424553 355331 67
The Folder object;s collections% properties% and methods are described below'
Collections
Collection Description
Files Returns a collection of all the files in a specified folder
SubFolders Returns a collection of all subfolders in a specified folder
Properties
Property Description
Attributes Sets or returns the attributes of a specified folder
>atereated Returns the date and time when a specified folder was created
>ate!astAccessed Returns the date and time when a specified folder was last
accessed
>ate!astodified Returns the date and time when a specified folder was last
modified
>rive Returns the drive letter of the drive where the specified folder
resides
1sRootFolder Returns true if a folder is the root folder and false if not
Bame Sets or returns the name of a specified folder
ParentFolder Returns the parent folder of a specified folder
Path Returns the path for a specified folder
7/17/2019 ASP Object
http://slidepdf.com/reader/full/asp-object-568c48fd9cde8 20/22
ShortBame Returns the short name of a specified folder 4the L.( namin"
convention5
ShortPath Returns the short path of a specified folder 4the L.( namin"
convention5
SiEe Returns the siEe of a specified folder
T&pe Returns the t&pe of a specified folder
Methods
Method Description
op& opies a specified folder from one location to another
>elete >eletes a specified folder
ove oves a specified folder from one location to another
reateTextFile reates a new text file in the specified folder and returns a
TextStream object to access the file
ASP Diction!ry Object
The >ictionar& object is used to store information in name0value pairs 4referred to as
$e& and item5
Examples
>oes a specified $e& exist@
This example demonstrates how to first create a >ictionar& object% and then use the
/xists method to chec$ if a specified $e& exists.
Return an arra& of all items
This example demonstrates how to use the 1tems method to return an arra& of all the
items.
Return an arra& of all $e&s
This example demonstrates how to use the Me&s method to return an arra& of all the
$e&s.
Return the value of an item
This example demonstrates how to use the 1tem propert& to return the value of an
item.
7/17/2019 ASP Object
http://slidepdf.com/reader/full/asp-object-568c48fd9cde8 21/22
Set a $e&
This example demonstrates how to use the Me& propert& to set a $e& in a >ictionar&
object.
Return the number of $e&0item pairs
This example demonstrates how to use the ount propert& to return the number of$e&0item pairs.
The !ictionary Object
The >ictionar& object is used to store information in name0value pairs 4referred to as
$e& and item5. The >ictionar& object mi"ht seem similar to Arra&s% however% the
>ictionar& object is a more desirable solution to manipulate related data.
omparin" >ictionaries and Arra&s'
• Me&s are used to identif& the items in a >ictionar& object
• ou do not have to call Re>im to chan"e the siEe of the >ictionar& object
• When deletin" an item from a >ictionar&% the remainin" items will
automaticall& shift up
• >ictionaries cannot be multidimensional% Arra&s can
• >ictionaries have more built3in functions than Arra&s
• >ictionaries wor$ better than arra&s on accessin" random elements fre6uentl&
• >ictionaries wor$ better than arra&s on locatin" items b& their content
The followin" example creates a >ictionar& object% adds some $e&0item pairs to it%
and retrieves the item value for the $e& "r'
<%
im d
Set d=Server.CreateObject("Scripting.ictinary")
d.6dd "re","ed"
d.6dd "gr","-reen"
d.6dd "bl","8l$e"
d.6dd "pi","9in:"
espnse.rite("*e val$e f :ey gr is " / d.;tem("gr"))
%+
*utput'
*e val$e f :ey gr is -reen
The >ictionar& object;s properties and methods are described below'
Properties
Property Description
ompareode Sets or returns the comparison mode for comparin" $e&s in a
7/17/2019 ASP Object
http://slidepdf.com/reader/full/asp-object-568c48fd9cde8 22/22
>ictionar& object
ount Returns the number of $e&0item pairs in a >ictionar& object
1tem Sets or returns the value of an item in a >ictionar& object
Me& Sets a new $e& value for an existin" $e& value in a >ictionar&object
Methods
Method Description
Add Adds a new $e&0item pair to a >ictionar& object
/xists Returns a 2oolean value that indicates whether a specified $e&
exists in the >ictionar& object
1tems Returns an arra& of all the items in a >ictionar& object
Me&s Returns an arra& of all the $e&s in a >ictionar& object
Remove Removes one specified $e&0item pair from the >ictionar& object
RemoveAll Removes all the $e&0item pairs in the >ictionar& object