Notice: This website is an unofficial Microsoft Knowledge Base (hereinafter KB) archive and is intended to provide a reliable access to deleted content from Microsoft KB. All KB articles are owned by Microsoft Corporation. Read full disclaimer for more details.

How To Dynamically Include Files in Active Server Pages


Summary

Since Active Server Pages (ASP) pages are compiled and executed before being sent to the client (as static HTML), trying to use a variable in place of a file name in a Server Side Include (<!-- #include PathType = FileName -->) fails. To include a file in your ASP page, you could include code similar to the following that reads in a file and displays it.

↑ Back to the top


More Information

<% ' The name of the file to display was passed by a form using GET method

infil = Request.QueryString("file")

If infil <&>"" then

set fso = Server.CreateObject("Scripting.FileSystemObject")
set fil = fso.OpenTextFile(infil)

outstring = fil.ReadAll

' PRE tags preserve the format of the file

Response.write "<PRE>" & outstring & "</PRE><BR>"

End If
%>

The dynamically included file may contain any client-side code you wish, including HTML and JavaScript. However, ASP will NOT process server-side script in the file. This is because all the ASP code has already run when it includes the file and the server will not go back to read anything for server-side processing again.

↑ Back to the top


References

For additional information, please see the following article in the Microsoft Knowledge Base:

172024 INFO: Server Side Include Directives Not Processed by ASP

↑ Back to the top


Keywords: kbcodesnippet, kbdsupport, kbhowto, kbscript, kbbillprodsweep, kb

↑ Back to the top

Article Info
Article ID : 192144
Revision : 1
Created on : 1/7/2017
Published on : 1/4/2012
Exists online : False
Views : 211