Search Search

#1 worldwide
FREE Coding Lessons

since 1996
   THE BEST WAY to learn ASP & Asp.net!
Advertise Here!
click for details
Credits Host:
DiscountASP.net
Server Admin:
The "Team"
Contact Info.
Charles M. Carroll

my Blog
[prev. Lesson]  Response: Encoding URLs, HTML
     [next Lesson]  Include: Dynamic FileName

Include Files

The include option is the heart of making efficient ASP files and re-usable chunks. It basically has two forms and now we will present the forms and their differences:

<!--#include virtual="/whatever.asp"-->
would include any file on your site (in this example, whatever.asp is in the web server's root directory) but you must fully qualify the filename with a path.

<!--#include file="whatever.asp"-->
can include the whatever.asp file in  the directory of the script that contains the statement. It ASSUMES the current directory!

Example #1
<!--#include virtual="/sally/filename.asp"-->
could include a file from sally's directory, even if the page with this statement is (for example) in the /fred/finance folder.

Example #2:
<!--#include file="/sally/filename.asp"-->
will fail from fred's directory.

Example #3:
<!--#include file="../sally/filename.asp"-->
will succed from fred's directory but if the script that contains it is moved to a different level in the tree structure it will fail to locate the file. INCLUDE VIRTUAL is better if a script may be moved and is immune to relative path issues.

IMPORTANT: Include files are always processed and inserted before ASP scripts on the page are calculated. Thus a page with many IFs and SELECT CASEs that selectively include files in fact always include the file before the script begins executing.

There are many worthy charities!!. But perhaps help starving children in Africa or South America AND help Charles too. a $5 tip buys him lunch at McDonalds, a $20 tip buys his kid Hitoshi a new computer game, a $39 tip buys his daughter Michiko a few nice outfits. See our donor list.