ASP9-ASP Including Files

The #include directive is used to create functions, headers, footers, or elements that will be reused on multiple pages. The #include D...

The #include directive is used to create functions, headers, footers, or elements that will be reused on multiple pages.

The #include Directive

You can insert the content of one ASP file into another ASP file before the server executes it, with the #include directive. The #include directive is used to create functions, headers, footers, or elements that will be reused on multiple pages.

How to Use the #include Directive

Here is a file called "mypage.asp":

<html> 
<body> 
<h3>Words of Wisdom:</h3>
<p><!--#include file="wisdom.inc"--></p> 
<h3>The time is:</h3>
<p><!--#include file="time.inc"--></p>
</body> 
</html> 

Here is the "wisdom.inc" file:

"One should never increase, beyond what is necessary,
the number of entities required to explain anything."

Here is the "time.inc" file:

<%
Response.Write(Time)
%>

If you look at the source code in a browser, it will look something like this:

<html>
<body>
<h3>Words of Wisdom:</h3>
<p>"One should never increase, beyond what is necessary,
the number of entities required to explain anything."</p>
<h3>The time is:</h3>
<p>11:33:42 AM</p>
</body>
</html>


Syntax for Including Files

To include a file in an ASP page, place the #include directive inside comment tags:

<!--#include virtual="somefilename"-->
or
<!--#include file ="somefilename"-->

The Virtual Keyword

Use the virtual keyword to indicate a path beginning with a virtual directory.
If a file named "header.inc" resides in a virtual directory named /html, the following line would insert the contents of "header.inc":

<!-- #include virtual ="/html/header.inc" -->

The File Keyword

Use the file keyword to indicate a relative path. A relative path begins with the directory that contains the including file.

If you have a file in the html directory, and the file "header.inc" resides in html\headers, the following line would insert "header.inc" in your file:

<!-- #include file ="headers\header.inc" -->

Note that the path to the included file (headers\header.inc) is relative to the including file. If the file containing this #include statement is not in the html directory, the statement will not work.

Tips and Notes

In the sections above we have used the file extension ".inc" for included files. Notice that if a user tries to browse an INC file directly, its content will be displayed. If your included file contains confidential information or information you do not want any users to see, it is better to use an ASP extension. The source code in an ASP file will not be visible after the interpretation. An included file can also include other files, and one ASP file can include the same file more than once.

Important: Included files are processed and inserted before the scripts are executed.
The following script will not work because ASP executes the #include directive before it assigns a value to the variable:

<%
fname="header.inc"
%>
<!--#include file="<%=fname%>"-->

You cannot open or close a script delimiter in an INC file. This script will not work:

<%
For i = 1 To n
  <!--#include file="count.inc"-->
Next
%>

But this script will work:

<% For i = 1 to n %>
<!--#include file="count.inc" -->
<% Next %>


Name

ADO,131,ASP,3,C++,61,CORE JAVA,1,CSS,115,HTML,297,index,5,JAVASCRIPT,210,OS,47,PHP,65,SAD,53,SERVLETS,23,SOFTWARE ENGINEERING,245,SQL,71,TCP/IP,1,XHTML,9,XML,18,
ltr
item
Best Online Tutorials | Source codes | Programming Languages: ASP9-ASP Including Files
ASP9-ASP Including Files
Best Online Tutorials | Source codes | Programming Languages
https://www.1000sourcecodes.com/2012/10/asp9-asp-including-files.html
https://www.1000sourcecodes.com/
https://www.1000sourcecodes.com/
https://www.1000sourcecodes.com/2012/10/asp9-asp-including-files.html
true
357226456970214079
UTF-8
Loaded All Posts Not found any posts VIEW ALL Readmore Reply Cancel reply Delete By Home PAGES POSTS View All RECOMMENDED FOR YOU LABEL ARCHIVE SEARCH ALL POSTS Not found any post match with your request Back Home Sunday Monday Tuesday Wednesday Thursday Friday Saturday Sun Mon Tue Wed Thu Fri Sat January February March April May June July August September October November December Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec just now 1 minute ago $$1$$ minutes ago 1 hour ago $$1$$ hours ago Yesterday $$1$$ days ago $$1$$ weeks ago more than 5 weeks ago Followers Follow THIS PREMIUM CONTENT IS LOCKED STEP 1: Share to a social network STEP 2: Click the link on your social network Copy All Code Select All Code All codes were copied to your clipboard Can not copy the codes / texts, please press [CTRL]+[C] (or CMD+C with Mac) to copy Table of Content