V
Active Server Pages
What is Active Server Pages?
Microsoft Active Server Pages (ASP) is a server-side scripting environment that you can use to create and run dynamic, interactive, high-performance web server applications. When your scripts run on the server rather than on the client, your web server does all the work involved in generating the HTML pages that you send to browsers. You need not worry whether a browser can process your pages: your web server does all the processing for it. You need only a working knowledge of HTML to begin using ASP. Take a look at A Brief History of Hypertext to better understand ASP's place in the evolution of the Web, as well as the powerful set of features ASP provides.
Active Server Pages is a feature of and can be used with the following web servers:
Microsoft Internet Information Server version 3.0 or Later on Windows NT Server
Microsoft Peer Web Services Version 3.0 on Windows NT Workstation
Microsoft Personal Web Server on Windows 95
A Script is a series of sentences placed one below the other in the form of a paragraph. Each sentence tells CPU what is should be doing at that moment in time. The sentences will be written in the syntax (grammar) of the scripting language of choice. Thus the paragraph created (which clubs together all the sentences) will be the 'Script'.
Executing a script sends the series of commands to a scripting engine, which interprets and relays them to the computer's CPU. Scripts are written in languages that have specific syntax hence, to use a given scripting language, the web server must have a scripting engine that understands the language. ASP provides scripting engines for the VBScript and JScript scripting languages. VBScript is the default scripting language for ASP.
Some popular web-related scripting languages include VBScript and JavaScript. When creating an ASP page, U can use one of four programming languages. VBScript, JScript, PerlScript, Python. An ASP page must contain an .ASP Extension.
A web-server is a computer that contains all the web-pages for a particular web-site and has special software installed to send these web pages to web browsers that request them.
The client can't tell the difference between an ASP page and a static web page as in both the cases it receives just HTML. When the web server processes an ASP page, all the programmatic code is interpreted on the server - none of it is sent to the client. The web-server determines whether the client is requesting a static HTML page or an ASP page by the extension of the web page being requested.
The Active Server Pages Model
An ASP script begins to run when a browser requests an .asp file from your Web server. Your Web server then calls ASP, which reads through the requested file from top to bottom, executes any commands, and sends an HTML page to the browser.
Differences between Client-Side Scripting and Server-Side ASP Code
Client-Side Scripting: - A client-side script is not processed at all by the web server, only by the client. It is the client's responsibility to execute any and all client-side scripts.
Server-Side Scirpting: - Server-side scripts are completely processed on the Web server. The client does not receive any code from the server-side scripts; rather, the client receives just the output of the server-side scripts. Client-side scripts and Server-side scripts cannot interact with one another because the client-side scripts are executed on the client, after the server-side scripts have finished processing completely.
How Static HTML Pages Work?
Internet is built on a client/server foundation. That means that there are two parts we must look at when dissecting an Internet transaction: the client and the server. The client is the web browser, be it Internet Explorer, Netscape, Lynx, Opera, or whatever. The server is the web server on which the HTML page exists.
The entire process of retrieving a web page goes like this:
You type in the URL into your browser, for example
Your browser finds the appropriate web server, and to that server says, "I need to look at the file /index.html, please."
The web server locates the file /index.html and sends it to the browser as HTML text.
The browser collects this text and parses it, determining how to display those colorful animated gifs and blinking text we've all come to love.
It's that simple. The transaction has just three simple steps:
• the client requests the document,
• the web server sends the document,
• the client decides how to display it.
How ASP Pages Work?
With ASP, however, there are some additional steps are taken on the server before the HTML text is sent back to the client. Let's look at what happens with ASP:
You type in the URL into your browser, for example
Your browser finds the appropriate web server, and to that server says, "I need to look at the file /default.asp, please."
The web server locates the file /default.asp and parses out the ASP code, turning the entire ASP code into applicable HTML code. ASP code is code in-between the ASP script delimiters () or in OBJECT tags with the RUNAT=Server property set. Since the entire ASP is parsed into HTML, the client sees absolutely no ASP code.
The browser collects this HTML text and parses it, determining how to display those colorful animated gifs and blinking text we've all come to love.
You'll note that there are again just three steps, although the second step is a bit more involved. The whole process starts with the client requesting a file with .ASP extension. The web server notes the extension, and since it has an .ASP extension (as opposed to a .txt, .htm or .html), the server parses the contents of the requested file before sending it to the client. So when you view an ASP file through IE or Netscape, your browser doesn't know that the .asp file is any different from a standard .html file
One of the things that make ASP a bit tricky for beginners is the fact that there are two kinds of scripting:
• client-side scripting
• server side scripting
Client-side scripting is HTML code that the browser interprets. For example, you can have a message box appear when a page is loaded by adding:
alert("Hello, world!");
at the bottom of your HTML page. This is client-side scripting. The web server makes no note of client-side code; it just sends it to the client like regular HTML text. It is the client's responsibility to process client-side scripts.
Server-side scripts are scripts that the server processes. ASP is a server-side script, since the web server completely processes all ASP scripts before sending the HTML content to the client. Since server-side scripts are handled by the server, the client does not interact with the server-side scripts. In fact, with ASP, since all ASP code is processed before the client obtains the server-side script, it is impossible for the ASP to make use of client-side actions without requiring a round trip to the server.
You can insert server-side variables into client-side script. Since the server-side script will be processed before the client receives the HTML content, and since client-side scripts are synonymous with HTML content, you can write server-side script variables to the client-side scripts rather simply.
alert (" ");
What you cannot do is have server-side script make use of client-side variables, methods, or events. Since the server-side script has completely been processed by the time any client-side code is processed, client-side code cannot impact the server-side code in any way.
What is an .asp File?
Active Server Pages (ASP) is built around files with the file name extension .asp. An .asp file is a text file and can contain any combination of the following:
Text
HTML tags
Script commands. A script command instructs your computer to do something, such as assign a value to a variable.
It’s easy to create an .asp file: Just rename any HTML file, replacing the existing .htm or .html file name extension with .asp. To make the .asp script file available to web users, save the new file in a web publishing directory. When you view the file with your browser, you see that ASP processes and returns HTML, just as before.
What is a Script?
A script is a series of script commands. A script can, for example:
Assign a value to a variable. A variable is a named storage location that can contain data, such as a value.
Instruct the Web server to send something, such as the value of a variable, to a browser. An instruction that sends a value to a browser is an output expression.
Combine commands into procedures. A procedure is a named sequence of commands and statements that acts as a unit.
Executing a script sends the series of commands to a scripting engine, which interprets and relays them to your computer. Scripts are written in languages that have specific rules; thus, if you want to use a given scripting language, your server must run the scripting engine that understands the language. ASP provides scripting engines for the VBScript and JScript scripting languages. Your primary scripting language—that is, the language that ASP assumes you are using if you don't specify a language—is VBScript by default.
Delimiters
HTML tags are differentiated from text by delimiters. A delimiter is a character or sequence of characters that marks the beginning or end of a unit. In the case of HTML, these delimiters are the less than () symbols. Similarly, ASP script commands and output expressions are differentiated from both text and HTML tags by delimiters. ASP uses the delimiters to enclose script commands. For example, the command assigns the value climbing to the variable sport. ASP uses the delimiters to enclose output expressions. For example, the output expression sends the value climbing (the current value of the variable) to the browser.
Statements
A statement, in VBScript and other scripting languages, is a syntactically complete unit that expresses one kind of action, declaration, or definition. The conditional If...Then...Else statement that appears below is a common VBScript statement.
=#12:00:00 AM# And Time < #12:00:00 PM# Then
greeting = "Good Morning!"
Else
greeting = "Hello!"
End If
%>
This statement stores either the value "Good Morning!" or the value "Hello!" in the variable greeting. It does not send any values to the client browser. The following lines send the value, in green, to the client browser:
Thus, a user viewing this script before 12:00 noon (in the Web server’s time zone) would see Good Morning!
A user viewing the script at or after 12:00 noon would see Hello!
Script Tags
The statements, expressions, commands, and procedures that you use within script delimiters must be valid for your default primary scripting language. ASP is shipped with the default primary scripting language set to VBScript. However, with ASP you can use other scripting languages; just use the HTML script tags and , together with the LANGUAGE and RUNAT attributes, to enclose complete procedures written in any language for which you have the scripting engine. For example, the following .asp file processes the VBScript function Add.
Comments and Concatenation
Single quote is used to give comment to lines in ASP. There is no multi line comment.
& character is used for concatenation.
Hello World!!!!
Now let us write our first program for Hello World….
Hello, World !
Displaying Date
To display date in your web page, Date function is used. This gives current date. To display current time, use Time function. To display both date and time use Now function.
Date and Time
From the current date and time user can also get the individual elements like Year, Date, Month, Hour, Minute and Second by using above functions.
Date and Time
Variables and Constructs
A variable is declared using dim keyword while using VBScript as scripting language. All variables are of type variant. The variable type is defined when the value is stored in it. The programmer need not to worry about the type of variable. By default variable declaration is not compulsory. However, it is best practice to always declare the variable before using it. Option explicit directive is used to make variable declaration compulsory.
Option Explicit must compulsorily be the first line of your ASP page else, the server generates error.
A variable is declared using var keyword while using JavaScript as scripting language. While using JavaScript, ASP commands should be ended with semicolon.
If-Then-Else
Example:
Some important points should be followed:
• The condition after the If must be followed by the Then keyword.
• If only a single statement is to be executed in the Then block, it may directly follow the Then on the same line. If there are multiple statements to execute in the Then-block, the first statement should begin on the line after Then.
• The Else-block is optional.
• The complete set of statements in the Then-block as well as the Else block need to be “closed” by the End If keyword. This is very important, and the source of many hard-to-locate errors.
For-Next Loop
Example:
Next keyword is used to indicate the end of For loop. Each Next statement encountered is automatically assumed to complete the immediately preceding For statement.
For-Each Loop
To iterate through the items in a collection one by one, for-each loop is used.
Including Other Files
Server-Side Includes (SSI) is a mechanism you can use to insert information into a file prior to processing. As we have the #include statement in C, we have the #include directive here. The purpose is exactly similar: #INCLUDE actually includes the said file at the given location. Any script that is present within that file is automatically executed. Include files are typically used to store application-wide functions and procedures, as well as various utility functions, You can put such functions in 1 file, and include that in all files you need.
Use the following syntax:
Here you must type either VIRTUAL or FILE, which are keywords that indicate the type of path you are using to include the file, and filename is the path and file name of the file you want to include. Included files do not require a special file-name extension; however, Microsoft recommends giving included files an .inc file-name extension to distinguish them from other types of files.
Using the Virtual Keyword
Use the Virtual keyword to indicate a path beginning with a virtual directory. For example, if a file named footer.inc resides in a virtual directory named /myapp, the following line would insert the contents of footer.inc into the file containing the line:
Using the File Keyword
Use the File keyword to indicate a relative path. A relative path begins with the directory that contains the including file. For example, if you have a file in the directory myapp, and the file header1.inc is in myapp/headers, the following line would insert header1.inc in your file:
Note that the path to the included file, headers/header1.inc, is relative to the including file; if the script containing this include statement is not in the directory /myapp, the statement would not work.
Including Files: Tips and Cautions
An included file can, in turn, include other files. An .asp file can also include the same file more than once, provided that the statements do not cause a loop. For example, if the file first.asp includes the file second.inc, second.inc must not in turn include first.asp. Nor can a file include itself. ASP detects such loop or nesting errors, generates an error message, and stops processing the requested .asp file.
ASP includes files before executing script commands. Therefore, you cannot use a script command to build the name of an included file. For example, the following script would not open the file header1.inc because ASP attempts to execute the #Include directive before it assigns a file name to the variable name.
Scripts commands and procedures must be entirely contained within the script delimiters , the HTML tags and , or the HTML tags and . That is, you cannot open a script delimiter in an including .asp file, and then close the delimiter in an included file; the script or script command must be a complete unit.
For example, the following script would not work:
Next
%
The following script would work:
Collections
A collection is similar to a data structure or array. Individual items in the collection are accessed via a unique key assigned to that item. They give unique and extended information about the object. In a large company, you can have a manufacturing component, a sales component, a human resources component, and so on. In making an analogy to ASP object collections, think of these company components as exposing specific attributes of the company.
ASP OBJECTS (BUILT IN OBJECTS)
✓ Request Object
The Request object provides access to all of the information that is passed in a request from the browser to the server. This information is stored among five types of Request collections.
Properties
1) TotalBytes
Description: This is the read only property. It specifies the total number of bytes the client is sending in the body of the request. The value returned by TotalBytes can be used as the argument of Request.BinaryRead(Count).
Syntax: Request.TotalBytes
Exqmple:
Name:
Age:
Sex:
Methods
1) BinaryRead
Description: This method retrieves the data that was sent to the server from the user as part of an HTTP POST (i.e. an HTML FORM request). The data read is stored in an array which is a variant, structure-like array that, in addition to storing the data.
You can write binary data into the response stream (info sent to a client) by using the Response.BinaryWrite(BinaryData) method. The BinaryData argument is simply the output (the SafeArray) from Request.BinaryRead. For example, you could retrieve an image from a database with Request.BinaryRead and send it to a client using Response.BinaryWrite. Using Request.Form after calling BinaryRead, and vice-versa, will cause an error. There is one mandatory argument.
Syntax: Request.BinaryRead(Count)
where,
count: contains the number of bytes to read
Example:
Collections
1) ClientCertificate
Description: This collection retrieves the certification fields from a request issued by the web browser. If a web browser uses the SSL protocol (in other words, it uses a URL starting with https:// instead of http://) to connect to a server , the browser sends the certification fields. SSL also known as Secure Socket Layer is be used to send data in a secure way. If no certificate is sent, the ClientCertificate collection returns EMPTY.
Syntax: Request.ClientCertificate(Key [SubField])
where,
Key: is used to specify the name of the field to retrieve from the client certification, a compulsory argument. Possible values are:
Issuer: is a string containing the subfield values that provide information about the issuer of the certificate.
SerialNumber: is a string that contains the certification serial number.
Subject: is a string containing the subfield values that provide information about the subject of the certificate.
ValidFrom: is the date when the certificate becomes valid.
ValidUntil: is the expiration date of the certificate
SubField: is used to get an individual field in Issuser or Subject key
SubField: This is the optional argument which is used only with the Issuer or the Subject key fields. It is added to the key field as a suffix. Possible values are:
C: is the name of the country of origin.
CN: is the common name of the user.
GN: is a given name.
I: is a set of initials.
L: is a locality.
O: is the company or organization name.
OU: is the name of the organizational unit.
S: is a state or province.
T: is the title of the person or organization.
Example:
This certification is valid from
until
2) Cookies
Description: The Cookies collection property contains the values of the cookies sent in the request. The Cookies collection property allows you to access the values of the browser cookies sent in by requests. Cookies are small files, which stores information on the clients system. Websites like Hotmail, Yahoo and even TopXML uses cookies. Some websites like GMail doesn’t even work if you have cookies disabled. These mentioned websites uses cookies to store the username and password in a cookie, so that each time you visit the website, you don’t need to login again. You can either create a new cookie or override the existing value.
Syntax: Request.Cookies(cookie name)[(key)|.attribute]
where,
cookiename: specifies the cookie whose value should be retrieved.
key: specifies which value from the cookie dictionary to retrieve.
attribute: The optional argument which is the boolean variable HasKeys.
True indicates that the cookie contains keys.
False indicates that the cookie does not contains keys
To determine whether a cookie is a cookie dictionary (whether the cookie has keys), use the following script.
Example:
3) Form
Description: The Form collection allows you to retrieve the information input into an HTML form on the client and sent to the server using the POST method. This information resides in the body of the HTTP request sent by the client. Most forums use this property to post new threads or replies.
Syntax:
Request.Form(element)[(index)|.Count]
where,
element: is the name of the element which is used to retrieve a value.
index: is an optional parameter which is used when the element argument has more than one value. It is an integer, ranging from 1 to Request.Form(Element).Count, which is used to select values from a element. Count is the total number of multiple values.
Example:
First Name:
Favourite IceCream Flavour:
Vanilla
Chocolate
Strawberry
If you refer to an element without an index and that element contains multiple values, your code will return a comma-delimited string.
4) Query String
Description: The QueryString collection retrieves the values of the variables in the HTTP query string. The HTTP query string is specified by the values following the question mark (?). Several different processes can generate a query string. For example, the anchor tag
string sample
Generates a variable named “string” with the value "this is a sample". Query strings are also generated by sending a form, or by a user typing a query into the address box of their browser. The Request.QueryString property can be used to retrieve the values from a form, which is posted via the GET method. The query string stores the values in a pair combination after the? sign in the URL. It looks like this: Elementname=Value.
The QueryString collection is less capable than the Form collection, since there is a limit to the amount of data that can be sent in the header of an HTTP request. This limit is around 2000 characters. More characters than this, sent as part of the QueryString, will not be processed, although the script still executes.
Syntax:
Request.QueryString(variable)[(index)|.Count]
where,
variable: specifies the name of the variable in the query string whose value is to be retrieve.
index: is the optional argument which is used when the variable argument has more than one value. It is an integer, ranging from 1 to Request.QueryString(Variable).Count, which is used to select values from the variable. Count is the total number of multiple values.
Example:
Username:
5) ServerVariables
Description: The ServerVariables collection retrieves the values of predefined server environmental variables in the context of the client’s specific HTTP request of the web server. This allows access to the HTTP headers.
Syntax:
Request.ServerVariables (server environment variable)
where,
ALL_HTTP: This variable can be used to retrieve all HTTP headers. This variables places the HTTP_ prefix before the header name and the header name is always in capital.
ALL_RAW: This variable retrieves all headers in raw form. The values appear in the same as they are sent. It does not add a prefix like All_HTTP does.
APP_POOL_ID: This variable returns the name of the application pool that is running in IIS worker process. This variable is not available in IIS 5.1 or below. Running this server variable on IIS 6.0 returns: DefaultAppPool
APPL_MD_PATH: This variable can be used to retrieve the metabase path of the application. Running this on my localhost returns: APPL_MD_PATH: /LM/W3SVC/1/Root/ASP_Examples
APPL_PHYSICAL_PATH: This variable can be used to retrieve the physical path corresponding to the metabase path in APPL_MD_PATH. On my system when I run the asp examples for this reference, it returns:
APPL_PHYSICAL_PATH: C:\Simulate_D\Customers\TopXML\References\ASP_Examples\
AUTH_PASSWORD: This variable retrieves the password entered in the client's authentication dialog. This variable is available only if basic authentication is used.
AUTH_TYPE: This is the authentication method that the server uses to validate users when they access a protected script. If you are not using any authentication it will return: Negotiate.
AUTH_USER: This is the name of the user. Running this on my localhost returns: SONU_LAPTOP\sonu (in the format machinename\login)
CACHE_URL: This value returns the name of the URL. It is only used in ISAPI applications. This value can be only used for IIS 5.1 or below.
CERT_COOKIE: This is the unique ID from the client certificate. It is returned as a string.
CERT_FLAGS: CERT_FLAGS is a two-bit value, bit 0 and bit 1. Bit 0 returns 1 if the client certificate is available. If it's invalid then bit 1 return 1. Invalid means the issuer is not found in the list of verified certificate issuers that resides on the web server). Note that these two bit values correspond to ceCertPresent and ceUnrecognizedIssuer constants.
CERT_ISSUER: The issuer of the client certificate, if one exists. The value of this element is a comma-delimited string that contains the subfields for each of the possible subelements described in the Issuer element section of the ClientCertificate collection explanation earlier in this chapter.
CERT_KEYSIZE: This value can be used to return the number of bits in a SSL connection. For example 64 or 128.
CERT_SECRETKEYSIZE: This value can be used to return the number of bits in the server certificate. For example 1024.
CERT_SERIALNUMBER: his value returns the serial number of the client certificate.
CERT_SERVER_ISSUER: This value returns the issuer field of the server.
CERT_SERVER_SUBJECT: This value returns the subject field of the server certificate.
CERT_SUBJECT: This value returns the subject field of the client certificate. This returns a comma-delimited string containing the subfields described in the Subject element section of the ClientCertificate collection description.
CONTENT_LENGTH: This value returns the length of the content. Running this example on my localhost returns: 0
CONTENT_TYPE: This value returns the type of the content, which can be GET, POST or PUT.
GATEWAY_INTERFACE: This value returns the revision of the CGI specification used by the server. On my localhost it returns: CGI/1.1
HTTP_ [HeaderName]: The value sent in the HTTP header called headername. To retrieve the value of any HTTP header not mentioned in this list (including custom headers), you must prefix the header name with HTTP_. Attempting to retrieve a nonexistent header returns an empty string, not an error.
HTTP_ACCEPT: This value returns the value of the accept header, which contains a list of accepted formats like: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/vnd.ms-excel. On my system it returns: */*
HTTP_ACCEPT_LANGUAGE: This value returns the language, which is used for the content. On my system it returns en-us
HTTP_COOKIE: This value returns the cookie string. On my system it returns: _Tab_Admin_Preview0=True;_Module4_Visible=true;Module335_Visible=true; .DOTNETNUKE=265948BAB1E6ACCDF503CBA5A4C12...
HTTP_REFERER: This value returns the original URL when a redirect has occurred. It can be used in website statistics to show the original URL from where the visitor came from.
HTTP_USER_AGENT: This value returns information about the client browser. On my system it returns: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SYMPA; MyIE2; SV1; .NET CLR 1.1.4322)
HTTPS: This value returns either ON if the request was made securely or OFF if the request came through a non-secure channel. When used on the URL the returned result is OFF. When used on the URL the returned result is ON.
HTTP_KEYSIZE: This value returns the number of bits in a SSL connection.
HTTP_SECRETKEYSIZE: This value can be used to return the number of bits in the server certificate.
HTTPS_SERVER_ISSUER: This value returns the issuer field of the server certificate.
HTTPS_SERVER_SUBJECT: This value returns the subject field of the server certificate.
INSTANCE_ID: This value returns the ID of the IIS instance. On my localhost it returns: 1
INSTANCE_META_PATH: This value is the meta base path for the instance of IIS that responds to a request. On my localhost it returns: /LM/W3SVC/1
LOCAL_ADDR: This value returns the server address on which the request came in. If you use localhost, then it will return: 127.0.0.1, but if you use the domain name then it will return the public IP.
LOGON_USER: This value returns the windows account that the user is logged in, regardless of the security type you are using (anonymous, basic, or Windows NT challenge/response). On my system it returns: SONU_LAPTOP\sonu
PATH_INFO: This value returns the extra path information. If yo use this variable on: then it will return: /mydir/test.asp
PATH_TRANSLATED: This value returns the translated version of the PATH_INFO from virtual to physical mapping.
QUERY_STRING: This value returns the query information stored in the string. When used on the URL: the returned result is only the querystring p=3&id=v20040906064945&ms=10&l=&sw=All
REMOTE_ADDR: This value returns the remote IP address.
REMOTE_HOST: This value returns the remote host name.
REMOTE_USER: This value returns an unmapped username sent by the user.
REQUEST_METHOD: This value returns the method used to make the request, such as GET, POST, HEAD
SCRIPT_NAME: This value returns the virtual path of the script. When used on this url it will return /asp/default.asp.
SERVER_NAME: This value returns the server’s hostname, DSN or IP. On it returns
SERVER_PORT: This value returns the port on which the request was sent. Usually its port 80.
SERVER_PORT_SECURE: This value returns the sting that contains either 0 or 1. 1 means that it is handled on a secure port and 0 means that it not a handled on a secure port. When used on the URL the returned result is 0. When used on the URL the returned result is 1.
SERVER_PROTOCOL: This value returns the name and revision about the request information protocol.
SERVER_SOFTWARE: This value returns the name and version of the software that response to the request. If IIS 5.1 is installed, this variable returns Microsoft-IIS/5.1.
URL: This value returns the base portion of the URL. When used on this url it will return /asp/default.asp.
Example:
✓ Response Object
As the Request object allows you to retrieve and manipulate information sent by the client browser in its HTTP request, the Response object gives you a great deal of control over the HTTP response to the client. It is the object which communicates between the server and the output which is sent to the client.
Properties:
1) Buffer
Description: The Buffer property indicates whether to buffer page output. When page output is buffered, the server does not send a response to the client until all of the server scripts on the current page have been processed, or until the Flush or End method has been called. The Buffer property cannot be set after the server has sent output to the client. For this reason, the call to Response.Buffer should be the first line of the .asp file.
Syntax: Response.Buffer [= flag]
where,
flag: specifies whether or not to buffer page output. Possible values are:
false - No buffering. This is the default value. The server sends output to the client as it is processed.
true - The server does not send output to the client until all of the ASP scripts on the current page have been processed, or until the Flush or End method has been called.
Example:
Page output is buffered
2) CacheControl
Description: The CacheControl allows you to set whether proxy servers serving your pages can cache your page. If your page’s content is large and doesn’t change often, you might want to allow proxy servers to cache the page and thus serve it faster to requesting client browsers.
Syntax:
Response.CacheControl [=control_header]
where,
control_header: A cache control header that can be set to "Public" or "Private", a string value.
Private - is default and indicates that only private caches may cache this page. Proxy servers will not cache pages with this setting.
Public - indicates public caches. Proxy servers will cache pages with this setting.
Example:
Please enter your bank account number and password to login
Number:
Password:
3) ContentType
Descripton: The ContentType property specifies the HTTP content type for the response. This string is usually of the format type/subtype where type is the general content category and subtype is the specific content type. If no ContentType is specified, the default is text/HTML.
Syntax: Response.ContentType [= contenttype ]
where,
contenttype : A string describing the content type. Possible Values are:
text/HTML, image/GIF, image/JPEG, text/plain
Example:
4) Expires
Description: The Expires property specifies the length of time before a page cached on a browser expires. If the user returns to the same page before it expires, the cached version is displayed.
Syntax: Response. Expires [= number]
where,
number: The time in minutes before the page expires. Set this parameter to 0 to have the cached page expire immediately.
Example:
5) Expires Absolute
Description: The Expires Absolute property specifies the date and time at which a page cached on a browser expires. If the user returns to the same page before that date and time, the cached version is displayed. If a time is not specified, the page expires at midnight of that day. If a date is not specified, the page expires at the given time on the day that the script is run.
Syntax: Response.ExpiresAbsolute [= [date] [time]]
where,
date: Specifies the date on which the page will expire. If this parameter is not specified, the page will expire at the specified time on the day that the script is run.
time: Specifies the time at which the page will expire. If this parameter is not specified, the page will expire at midnight of the specified day.
Example:
The following example specifies that the page will expire 15 seconds after 1:30 pm on May 31, 2002.
6) IsClientConnected
Description: The IsClientConnected property is a read-only property that indicates if the client has disconnected from the server since the last Response.Write. it evaluates to True if the client is still connected to the web server and returns False otherwise.
Syntax: Response.IsClientConnected ( )
Example:
The cookie has the following value:
✓ Session Object
You can use the Session object to store information needed for a particular user-session. Variables stored in the Session object are not discarded when the user jumps between pages in the application; instead, these variables persist for the entire user-session. The web server automatically creates a Session object when a user who does not already have a session requests a web page from the application. The server destroys the Session object when the session expires or is abandoned. One common use for the Session object is to store user preferences.
A user session can be initiated in one of three ways:
• A user not already connected to the server requests an Active Server Page that resides in an application containing a GLOBAL.ASA file with code for the Session_OnStart event.
• A user requests an Active Server Page whose script stores information in any session-scoped variable.
• A user requests an Active Server Page in an application whose GLOBAL.ASA file instantiates an object using the tag with the SCOPE parameter set to Session.
Note that a user session is specific to a given application on your web site. The web server identifies each user with a unique SessionID value. This SessionID variable is assigned to each user at the beginning of his session on the web server and is stored in memory on the web server. The SessionID is stored on the client by writing a cookie containing the SessionID to the user’s machine. This cookie is sent to the server each time the user makes a request. To identify the user, the server retrieves the cookie and matches it up with a SessionID held in memory.
What if the user has cookies turned off or is using an older browser that does not support the use of cookies? Well, if you are using Windows NT or Basic Authentication, you can identify the user from the LOGON_USER element of the Request object’s ServerVariables collection. From this information, you can retrieve user-specific data from a database or text files on the server. If you are not using Windows NT or Basic Authentication, you will likely not be able to identify the user.
Properties
1) CodePage
Description: Specifies or retrieves the code page that will be used by the web server to display dynamic content in the current script. A code page is a character set containing all the alphanumeric characters and punctuation used by a specific locale.
Syntax: Session.CodePage (= intCodePageValue)
where,
intCodePage: An unsigned integer corresponding to a specific character set installed on the server. Setting the CodePage property will cause the system to display content using that character set. Possible Values are:
932 – Japanese Kanji
950 – Chinese
1252 – American English (& most European languages)
Example:
2) SessionID
Description: A read-only value that uniquely identifies each current user’s session. Each session has a unique identifier that is generated by the server when the session is created. The session ID is returned as a LONG data type and is stored as a cookie on the client machine. During a user’s session, the user’s browser sends this cookie to the web server as a means of identifying the user. The SessionID property is generated the first time a user requests a page from the web server. The web server creates a value for the SessionID property using a complex algorithm and then stores this value in the form of a cookie on the user’s machine. Subsequently, each time the user requests a page from the web server, this cookie is sent to the server in the HTTP request header. The server is then able to identify the user according to his SessionID. The cookie is reinitialized only when the client restarts his browser or when the webmaster restarts the web server. Note that the SessionID cookie lasts on the client browser and is sent to (and recognized by) the web server until one of the two machines (client or web server) is restarted. This time period has nothing to do with the Timeout property of the Session object. For example, assume a user’s session ends or is abandoned by using the Abandon method of the Session object. Then the user (without having restarted his browser) revisits the site. Assuming also that the web server has not been restarted since the end of the last session, the web server will start a new session for the user but will use the same SessionID, which is again sent to the web server as part of the HTTP request. Only if both the client browser and the web server applications have not been restarted can you assume a SessionID uniquely identifies a user. Do not use this value as a primary key, for example, as it is reset anytime either browser or server is stopped and restarted. Browser that does not support cookies or that has cookies turned off will not send the SessionID as part of the HTTP request header. In this case, you must rely on some other method to identify users. To maintain information without using cookies, you could either append information from each request onto the QueryString or post the identifying information from a hidden form element on your page.
Syntax: Session.SessionID
Example:
3) Timeout
Description: This property specifies the timeout period assigned to the Session object for the application, in minutes. If the user does not refresh or request a page within the timeout period, the session ends.
Syntax: Session.Timeout (= intMinutes)
where,
intMinutes: Specifies the number of minutes that a session can remain idle before the server terminates it automatically. The default is 20 minutes.
Example:
Methods
1) Abandon
Description: The Abandon method destroys all the objects stored in a Session object and releases their resources. If you do not call the Abandon method explicitly, the server destroys these objects when the session times out. The Abandon method is actually processed by the web server after the rest of the current page’s script is processed. After the current page’s processing is complete, however, any page request by the user initiates a new session on the web server.
Syntax: Session.Abandon
Example:
Events
1) Session_OnEnd
Description: This event occurs when a session is abandoned or times out. Of the server built-in objects, only the Application, Server, and Session objects are available. The OnEnd event procedure, if it exists, resides in the GLOBAL.ASA file for the application that contains the requested page. One of the possible uses of the Session_OnEnd event is to write information concerning the user to a log file or other text file on the server for later use. If you intend to do this, there are several important points you must remember. First, before you can save any information, that information must be saved to a session variable because, as mentioned earlier, you do not have access to the Request object, which is the most common source of user information. You cannot use the AppendToLog method of the Response object, because the Response object is unavailable. In addition, if you intend to write directly to the web server’s hard drive, you must know the physical path of the file to which you want to write. This is because, although you do have access to the Server object, you cannot use its MapPath method in the Session_OnEnd event.
Syntax:
Sub Session_OnStart
. . .
End Sub
Sub Session_OnEnd
. . .
End Sub
Example:
In global.asa file,
Sub Application_OnEnd()
Application("totvisitors") = Application("visitors")
End Sub
Sub Application_OnStart
Application("visitors") = 0
End Sub
Sub Session_OnStart
Application.Lock
Application("visitors") = Application("visitors")+1
Application.UnLock
End Sub
Sub Session_OnEnd
Application.Lock
Application("visitors") = Application("visitors")-1
Application.UnLock
End Sub
In test file,
There are
online now!
2) Session_OnStart
Description: This event occurs when the server creates a new session. The server processes this script prior to executing the requested page. The Session_OnStart event is a good time for you to set any session-wide variables, because they will be set before any pages are accessed. All the built-in objects (Application, ObjectContext, Request, Response, Server, and Session) are available and can be referenced in the Session_OnStart event script. The Session_OnStart event procedure, if it exists, resides in the GLOBAL.ASA file for the application that contains the requested page. If the client’s browser does not support cookies or if the user has manually turned cookies off, the Session_OnStart event is processed every time the user requests a page from the site. No session is started or maintained. Like the OnEnd event, one of the possible uses of the OnStart event is to write information concerning the user to a log file or other text file on the server for later use. If you intend to do this, note that you cannot use the AppendToLog method of the Response object, and if you intend to write directly to the web server’s hard drive, you must know the physical path of the file to which you want to write. This is because, although you do have access to the Server object, just as in the OnEnd event of the Session object, you cannot use the MapPath method of the Server object in the Session_OnStart event.
Syntax:
Sub Session_OnStart
. . .
End Sub
Sub Session_OnEnd
. . .
End Sub
Example:
Same as above.
Collections
1) Contents
Description: The Contents collection holds any variables stored in the Session object. It also holds any objects created by calling Server.CreateObject.
Syntax: Session.Contents(key)
where,
key: Represents the name of a specific element in the collection.
Example:
Suppose you have stored the following user information in the Session object:
You can access an item by using the name you associated with the item when you stored it in the collection. For example, the following expression returns the string "Sam":
You could also access an item by using the index, or number, associated with an item. For example, the following expression retrieves the information stored in the second slot of the Session object and returns "Hello":
You can access items by name using a shorthand notation. ASP searches the collections associated with an object in a particular order. If an item with a particular name appears only once in an object's collections, you can eliminate the collection name:
2) StaticObjects
Description: This collection contains all of the objects with session-level scope that are added to the application through the use of the tag. You can use this collection to retrieve properties of a specific object in the collection. You also can use this collection to use a specific method of a given object in the collection. Objects instantiated using Server.CreateObject are not accessible through this collection. Objects created in the GLOBAL.ASA file are not actually instantiated on the server until the first time a property or method of that object is called. For this reason, the StaticObjects collection cannot be used to access these objects’ properties and methods until some other code in your application has caused them to be instantiated on the server.
Syntax: Session.StaticObjects(Key)
where,
key: Represents the name of a specific element in the collection.
Example:
strFirstObjName = Session.StaticObjects.Key(1)
The above line retrieves the name of the first element in the StaticObjects collection of the
Session object.
✓ Application Object
You can use the Application object to share information among all users of a given application. An ASP-based application is defined as all the .asp files in a virtual directory and its subdirectories. Because more than one user can share the Application object, there are Lock and Unlock methods to ensure that multiple users do not try to alter a property simultaneously. You can store values in the Application Collections. Information stored in the Application collections is available throughout the application and has application scope.
The Application object is initialized by IIS the moment the first client requests any file from within the given virtual directory. you can customize this initialization by including code in a special optional file called GLOBAL.ASA. It remains in the server’s memory until either the web service is stopped or the application is explicitly unloaded from the web server using the Microsoft Management Console. IIS allows you to instantiate variables and objects with application-level scope. This means that a given variable contains the same value for all clients of your application.
Methods
1) Lock
Description: The Lock method blocks other clients from modifying the variables stored in the Application object, ensuring that only one client at a time can alter or access the Application variables. If you do not call the Unlock method explicitly, the server unlocks the locked Application object when the .asp file ends or times out.
You cannot create a read-only variable by using a call to the Lock method without a corresponding call to Unlock, since IIS automatically unlocks the Application object. You do not have to call the Lock and Unlock methods in the Application_OnStart event procedure. The Application_OnStart event occurs only once regardless of the number of sessions that are eventually initiated.
Syntax: Application.Lock
Example:
2) Unlock
Description: The Unlock method enables other clients to modify the variables stored in the Application object after it has been locked using the Lock method. If you do not call this method explicitly, the web server unlocks the Application object when the .asp file ends or times out.
Syntax: Application.Unlock
Example:
Same as above...
Events
1) Application_OnStart
Description: The Application_OnStart event occurs before the first new session is created, that is, before the Session_OnStart event. Only the Application and Server built-in objects are available. Referencing the Session, Request, or Response objects in the Application_OnStart event script causes an error. The Application_OnStart event, if it exists, is the first code run on the server for a given Active Server Pages application. For this reason, it is the best place to initialize application-level variables.
Syntax:
Sub Application_OnStart
. . .
End Sub
Example:
2) Application_OnEnd
Description: The Application_OnEnd event is triggered when the ASP application itself is unloaded from the web server or when the application is stopped for some reason (i.e., the web service is stopped on the web server). Application_OnEnd is called only once per application. The code for this event procedure resides in the GLOBAL.ASA file and is processed after all other code in the file. It is in the code for the Application_OnEnd event that you will “clean up” after any application-scoped variables. Only the Application and Server built-in objects are available.
Syntax:
Sub Application_OnEnd
. . .
End Sub
Example:
Collections
1) Contents
Description: The Contents collection of the Application object contains all the application- level scoped variables and objects added to the current application through the use of scripts (not through the use of the tag).
Syntax: Application.Contents(Key)
where,
key: Represents the name of a specific element in the Contents collection.
Example:
You can initialize application-level variables and thus add elements to the Contents collection in one of two ways. First, you can initialize Application variables in the Application_OnStart event procedure in the GLOBAL.ASA file, as given below:
‘>>>>
‘This code resides in the GLOBAL.ASA file at the root of the current application.
Sub Application_OnStart
Application.Contents.Item(1) = "Georgia"
Application.Contents(2) = "Kentucky"
Application(3) = "Alabama"
Application.Contents.Item("STATE_FOURTH") = "California"
Application.Contents("STATE_FIFTH") = "Oregon"
Application("STATE_SIXTH") = "Washington"
End Sub
The above code creates six application-scoped variables, thus adding six elements to the Contents collection. Note that these variables will be instantiated and initialized only at the start of the application, not upon every visit to the site by subsequent users. These variables maintain the same values unless another script changes them for all pages and for all users.
Secondly, you can create application-scoped variables and thus add elements to the Contents collection inside any script on any page. The code is as below:
The above code gives the following output:
The paragraph tag: < P>
3) MapPath
Description: The MapPath method maps the specified relative or virtual path to the corresponding physical directory on the server. The MapPath method does not support relative path syntax (.) or (..). For example, the following relative path,
/MyDir/MyFile.txt
returns an error. The MapPath method does not check whether the path it returns is valid or exists on the server.
Syntax: Server.MapPath(path)
where,
path: A complete virtual path or a path relative to the path of the current script’s home directory on the server. The method determines how to interpret the string depending on if it starts with either a slash (/) or a backslash (\). If the strPath parameter begins with either of these characters, the string is assumed to be a complete virtual path. Otherwise, the physical path returned is the path relative the current script’s physical directory on the web server.
Example:
path to current directory
4) URLEncode
Description: Encodes a string that can then be sent over the address line as a query string.
Syntax: Server.URLEncode (string)
where,
string: specifies the string to encode.
Example:
✓ FileSystem Object
The FileSystem Object is the object that is used to manipulate the filesystem in Active Server Pages. Moving files, opening and reading text files, and looking at drive space are a few of the many functions of the FileSystem. The FileSystem Object actually contains five objects: the main Filesystem object, the Drive object, the Folder object, the File object, and the TextStream object.
FileSystem
The FileSystemObject object is used to access the file system on the server. This object can manipulate files, folders, and directory paths. It is also possible to retrieve file system information with this object.
Syntax: Scripting.FileSystemObject
Example:
Properties
1. Drives
Description: The Drives property returns a collection of all Drive objects on the computer. It is a read-only property
Syntax: [drivecoll=]FileSystemObject.Drives
Example:
Methods
2. BuildPath
Description: Builds the specificed folders on to the existing path.
Syntax:
Drive Object
The Drive object is used to return information about a local disk drive or a network share. The Drive object can return information about a drive's type of file system, free space, serial number, volume name, and more.
You cannot return information about a drive's content with the Drive object. For this purpose you will have to use the Folder object.
To work with the properties of the Drive object, you will have to create an instance of the Drive object through the FileSystemObject object. First; create a FileSystemObject object and then instantiate the Drive object through the GetDrive method or the Drives property of the FileSystemObject object.
The following code illustrates how the FileSystemObject is used to return a TextStream object that can be read from or written to:
Set fso = Server.CreateObject("Scripting.FileSystemObject")
Set a = fso.CreateTextFile("c:\testfile.txt", True)
a.WriteLine("This is a test.")
a.Close
In the preceding code, the CreateObject function returns the FileSystemObject (fso).
e Drives collection.
You can iterate the members of the Drives collection using a For Each...Next construct as illustrated in the following code:
Dim fso, d, dc, s, n
Set fso = CreateObject("Scripting.FileSystemObject")
Set dc = fso.Drives 'dc is now a drives collection
For Each d in dc
s = s & d.DriveLetter & " - "
If d.DriveType = 3 Then 'value-3 is for Remote Drives(Network Drives)
n = d.ShareName
ElseIf d.IsReady Then
n = d.VolumeName
End If
s = s & n & ""
Next
Response.write(s)
Methods (Totally 24 methods are there)
(1) CreateTextFile :-
Creates a specified file name and returns a TextStream object that can be used to read from or write to the file.
Syntax:
set txtstrobj= object.CreateTextFile(filename[, overwrite[, unicode]])
Filename –
string that identifies the file to create
Overwrite –
optional parameter, when set to true, overwrites the existing file (default false).
Unicode –
optional parameter, when set to true indicates that file is created as unicode file, ASCII otherwise.
Example
Set fso = CreateObject("Scripting.FileSystemObject")
Set a = fso.CreateTextFile("c:\testfile.txt", True) 'overwrites existing file
a.WriteLine("This is a test.") 'Writes a single line of text to the file
a.Close 'Closes the file
(2) OpenTextFile:-
Opens a specified file and returns a TextStream object that can be used to read from, write to, or append to the file.
Syntax:
set txtstrobj= object.OpenTextFile(filename[, iomode[, create[, format]]])
Filename - string that identifies the file to create
iomode - Optional. Indicates input/output mode. Can be one of three constants: ForReading ->1, ForWriting->2, or ForAppending->8.
create - optional. If set to true, creates a new file in case the file does not exist. (False Default)
format - optional. One of three Tristate values used to indicate the format of the opened file. If omitted, the file is opened as ASCII.
Tristate values
-2 => Open's file in System's default format
-1 => Opens file as Unicode
0 => Opens file in ASCII format.
Example :
Dim fso, f
Set fso = Server.CreateObject("Scripting.FileSystemObject")
Set f = fso.OpenTextFile("c:\testfile.txt", 2, True)
f.Write "Hello world!" 'Overwrites the file content with this text
f.Close
(3) GetDriveMethod :-
Returns a string containing the name of the drive for a specified path.
Syntax :
object.GetDriveName(path)
path - Required. The path specification for the component whose drive name is to be returned. The GetDriveName method returns a zero-length string ("") if the drive can't be determined.
Example :
Dim fso
Set fso = CreateObject("Scripting.FileSystemObject")
GetAName = fso.GetDriveName("c:\asp")
Response.write GetAName
Note :
The GetDriveName method works only on the provided path string. It does not attempt to resolve the path, nor does it check for the existence of the specified path.
(4) CreateFolder :-
Creates a folder.
Syntax :
object.CreateFolder(foldername)
foldername - String that identifies the folder to create. An error occurs if the specified folder already exists.
Example:
Dim fso, f
Set fso = CreateObject("Scripting.FileSystemObject")
Set f = fso.CreateFolder("c:\New Folder") 'creates a folder named New Folder
(5) CopyFolder :-
Recursively copies a folder from one location to another. (Copy command of dos)
Syntax :
object.CopyFolder source, destination[, overwrite]
source - A string folder specification, which can include wildcard characters, for one or more folders to be copied.
destination - string destination where the folder and subfolders from source are to be copied. Wildcard characters are not allowed.
overwrite - optional. indicates whether existing folders are to be overwritten or not. (default True)
Wildcard characters can only be used in the last path component of the source argument.
If destination does not exist, the source folder and all its contents gets copied. This is the usual case. If destination is an existing file, an error occurs. If destination is a directory, an attempt is made to copy the folder and all its contents. If a file contained in source already exists in destination, an error occurs if overwrite is False. Otherwise, it will attempt to copy the file over the existing file. If destination is a read-only directory, an error occurs if an attempt is made to copy an existing read-only file into that directory and overwrite is False.
(6) DeleteFolder :-
Deletes a specified folder and its contents.
Syntax :
object.DeleteFolder (folderspec[, force])
folderspec- name of the folder to be removed.
force - optional. When set to True, removes the read-only folder forcefully.
The DeleteFolder method does not distinguish between folders that have contents and those that do not. The specified folder is deleted regardless of whether or not it has contents.
An error occurs if no matching folders are found. The DeleteFolder method stops on the first error it encounters. No attempt is made to roll back or undo any changes that were made before an error occurred.
Example :
Set fso = CreateObject("Scripting.FileSystemObject")
fso.DeleteFolder("c:\new folder")
(7) MoveFolder :-
Moves one or more folders from one location to another. ( Like cut & paste of folder)
Syntax :
object.MoveFolder( source, destination )
source - . The path to the folder or folders to be moved. The source argument string can contain wildcard characters in the last path component only.
destination - The path where the folder or folders are to be moved. The destination argument can't contain wildcard characters.
Note :- If source contains wildcards or destination ends with a path separator (\), it is assumed that destination specifies an existing folder in which to move the matching files. Otherwise, destination is assumed to be the name of a destination folder to create. In either case, three things can happen when an individual folder is moved:
If destination does not exist, the folder gets moved. This is the usual case. If destination is an existing file, an error occurs. If destination is a directory, an error occurs.
An error also occurs if a wildcard character that is used in source doesn't match any folders. The MoveFolder method stops on the first error it encounters. No attempt is made to roll back any changes made before the error occurs.
Example :
Set fso = CreateObject("Scripting.FileSystemObject")
fso.MoveFolder "c:\abc", "c:\windows\desktop\"
(8) CopyFile :-
Copies one or more files from one location to another.
Syntax :
object.CopyFile source, destination[, overwrite]
source - string file specification, which can include wildcard characters, for one or more files to be copied.
destination - string destination where the file or files from source are to be copied. Wildcard characters are not allowed.
overwrite - optional. If True, files are overwritten; if False, they are not. default True.
(9) MoveFile :-
Moves one or more files from one location to another.
Syntax :
object.MoveFile source, destination
source - The path to the file or files to be moved. The source argument string can contain wildcard characters in the last path component only.
destination - The path where the file or files are to be moved. The destination argument can't contain wildcard characters.
(10) DeleteFile :-
Deletes a specified file.
Syntax :
object.DeleteFile filespec[, force]
filespec - The name of the file to delete. The filespec can contain wildcard characters in the last path component.
force - Optional. Boolean value that is True if files with the read-only attribute set are to be deleted; False (default) if they are not.
An error occurs if no matching files are found. The DeleteFile method stops on the first error it encounters. No attempt is made to roll back or undo any changes that were made before an error occurred.
Drive Object
Description
Provides access to the properties of a particular disk drive or network share.
Example
Set fso = CreateObject("Scripting.FileSystemObject")
Set d = fso.GetDrive(fso.GetDriveName("c:\"))
s = "Drive C:\ - "
s = s & d.VolumeName & ""
s = s & "Free Space: " & d.FreeSpace
s = s & " bytes"
Response.write s
Properties
(1) AvailableSpace - Returns the amount of space available to a user on the specified drive or network share.
(2) DriveType - Returns a value indicating the type of a specified drive.
Value is as under
0 -> Unknown
1 -> Removable Drive (floppy Drive, ZipDrive, etc)
2 -> Fixed Drive
3 -> Network Drive (Shared with your computer)
4 -> CD-ROM
5 -> RAM Disk
(3) IsReady - Returns True if the specified drive is ready; False if it is not.
For removable-media drives and CD-ROM drives, IsReady returns True only when the appropriate media is inserted and ready for access.
(4) TotalSize - Returns the total space, in bytes, of a drive or network share.
(5) VolumeName - Sets or returns the volume name of the specified drive. Read/write.
Folder Object
Provides access to all the properties of a folder.
Properties
(1) Attributes - Sets or returns the attributes of files or folders. Read/write or read-only, depending on the attribute.
value Description
0 Normal file. No attributes are set.
1 Read-only file. Attribute is read/write.
2 Hidden file. Attribute is read/write.
4 System file. Attribute is read/write.
8 Disk drive volume label. Attribute is read-only.
16 Folder or directory. Attribute is read-only.
32 File has changed since last backup. Attribute is read/write.
64 Link or shortcut. Attribute is read-only. (Alias)
128 Compressed file. Attribute is read-only.
(2) DateCreated - Returns the date and time that the specified file or folder was created. Read-only.
(3) Name - Sets or returns the name of a specified file or folder. Read/write.
(4) ParentFolder - Returns the folder object for the parent of the specified file or folder. Read-only.
(5) IsRootFolder - Returns True if the specified folder is the root folder; False if it is not.
File Object
Provides access to all the properties of a file.
Properties
Same as that of folder object (Except IsRootFolder)
(5) Type - Returns information about the type of a file or folder. For example, for files ending in .TXT, "Text Document" is returned.
TextStream Object
Facilitates sequential access to a text file.
Property
(1) Line - Read-only property that returns the current line number in a TextStream file.
(2) Column - Read-only property that returns the column number of the current character position in a TextStream file.
(3) AtEndOfLine - Read-only property that Returns True if the file pointer immediately precedes the end-of-line marker in a TextStream file; False if it is not.
(4) AtEndOfStream - Read-only property that Returns True if the file pointer is at the end of a TextStream file; False if it is not.
Note :- The AtEndOfLine and AtEndOfStream properties apply only to TextStream files that are open for reading; otherwise, an error occurs.
Method
(1) Close - Closes an open TextStream file.
(2) Read - Reads a specified number of characters from a TextStream file and returns the resulting string.
Syntax :
str = object.Read(noOfCharacters)
(3) ReadAll - Reads an entire TextStream file and returns the resulting string.
Note :
For large files, using the ReadAll method wastes memory resources. Other techniques should be used to input a file, such as reading a file line by line.
(4) ReadLine - Reads an entire line (up to, but not including, the newline character) from a TextStream file and returns the resulting string.
(5) Skip - Skips a specified number of characters when reading a TextStream file.
Syntax :
object.Skip(NoOfCharactersToBeSkipped)
(6) SkipLine - Skips the next line when reading a TextStream file.
Note :
Skipping a line means reading and discarding all characters in a line up to and including the next newline character. An error occurs if the file is not open for reading.
(7) Write - Writes a specified string to a TextStream file.
Syntax :
object.Write(string)
(8) WriteLine - Writes a specified string and newline character to a TextStream file.
Syntax :
object.WriteLine([string])
(9) WriteBlankLines - Writes a specified number of newline characters to a TextStream file.
Syntax :
object.WriteBlankLines(NoOfNewLines)
❖ Global.asa Reference
The Global.asa file is an optional file in which you can specify event scripts and declare objects that have session or application scope. It is not a content file displayed to the users; instead it stores event information and objects used globally by the application. This file must be named Global.asa and must be stored in the root directory of the application. An application can only have one Global.asa file.
Global.asa files can contain only the following:
Application events
Session events
Declarations
The scripts contained in the Global.asa file may be written in any supported scripting language. If multiple event or object scripts use the same scripting language, they can be combined inside a single set of tags.
................
................
In order to avoid copyright disputes, this page is only a partial summary.
To fulfill the demand for quickly locating and searching documents.
It is intelligent file search solution for home and business.