In a previous tip, I talked about how you can't dynamically include a file in your ASP file, but apparently my explanation was misunderstood, so here goes again. The standard server-side include directive looks something like this:
<!--#include virtual="/includes/header.asp" -->
This type of directive is processed before any ASP code is run, which means you can't dynamically build this statement and essentially can't dynamically choose an ASP file to run. The options presented in other articles where you wrap a block of code or an include with an If/Then statement still doesn't change the fact that both files are loaded into memory.
The alternate option you have if you're just loading client-side HTML/JavaScript code is to read the file using the FileSystemObject and a TextStream object and print it out to the console. Here's a routine I use to do that:
Sub IncludeFile(strFilename)
If strFilename = "" Then Exit Sub
On Error Resume Next
Dim objFSO, objFile, strContents
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile(Server.MapPath(strFilename), ForReading, False)
strContents = objFile.ReadAll
Response.Write strContents & vbCrLf
objFile.Close
Set objFile = Nothing
Set objFSO = Nothing
End Sub
This code assumes you have the Scripting Runtime referenced using a METADATA tag (see my previous tips as asptechniques.com for more information on this). Note that this code simply reads a file and immediately prints it to the output window. This means that you can't have ASP code in the files you read this way. I typically use this only for plain HTML files or JavaScript code when I need to dynamically specify a filename.