Go to: Articles List

Code Smarter Part 2 : Use Include Files

Along with encapsulating your code, the next best thing to do with this code is to place it in a file and include it. You can place all of your commonly used code in one simple file and include it.

There are two types of includes: virtual and absolute. Each is demonstrated below:

Virtual:
<!-- #include virtual="/includes/common.asp" -->

Absolute:
<!-- #include file="d:\inetpub\wwwroot\includes\common.asp" -->

Which is better? The virtual in my opinion. The reason I chose and always use virtual includes myself is because if I move that file to another website or web server the path will generally stay the same. Whereas if I were to use an absolute include file I might have to go change the drive letter and file structure.

Remember to place this code outside of the ASP script blocks.