Include Files
Added 29 Jul 2008
You can place all of your commonly used code in one simple file and include it in any number of other ASP files you want. So when you need to update one piece of code that is used throughout your application you can simply update it in one file ie the include file and every other page that uses the include file will automatically be updated.
The include file can come in handy for such things as functions, headers and footers and the connection string. Believe me it can save alot of maintenance and updating time.
Below is an example of how to use an include file:
There are two way of using an include file.
1. Virtual, using the 'virtual' keyword
2. Relative, using the 'file' keyword
In using the virtual keyword it assumes that you are starting from the webserver's root directory. You are not concerned with the relative path from the file that you will be including it in, but exactly where it is located starting from the root of the website.
The file keyword indicates a relative path so if the include file was in the folder 'test' then the relative path from the current folder might be
or if the file was in the same folder then it would simply be
So just to note that with virtual you are not concerned with the path relative to the file from which you will call the include file but its exact absolute position starting from the root directory of the website. Whereas with the file keyword you are concerned with the relative address from the file that you will be calling the include file from.
Remember to place this code outside of the ASP script blocks, ie not
within ASP delimiters <% %>
Include files can end with the "inc" extension. However, for security
reason i prefer using the "ASP" extension. Functions written in files
using the "inc" extension can be opened in a browser window and viewed.
Functions written in files using an "ASP" extension are not displayed
to the viewer, thus keeping the source code hidden from hackers.