Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Include file dynamically

Status
Not open for further replies.

cumap

IS-IT--Management
Jul 9, 2007
268
US
Hello all,
this is what I got
Code:
<%
if lcase(template)="default" then
%>
	<!--#include file="templates/default/header.asp"-->
<%
elseif lcase(template)="newtemplate" then
%>
	<!--#include file="templates/newtemplate/header.asp"-->
<%
else
%>
	<!--#include file="templates/temple/header.asp"-->
<%
end if
%>

I'd like to have this case even more dynamic by not knowing what the next case is going to be, all the If statement need to do is
Code:
<%
template = "x"
%>
<!--#include file=templates/<%=x%>/header.asp"-->
but this code is not working. I tried with OpenTextFile and ReadAll or Server.Execute but what I got from these methods are strictly TEXT and all of other asp code in the included file are not generated nor executed whatsoever.

Is there another way to include a asp file as dynamically as I described on the above?
 
You can use FileSystemObject to include a file containing VBScript.
 
That should have said:

You can use FileSystemObject to dynamically include a file containing VBScript. Like this:

Code:
Function getMappedFileAsString(byVal strFilename)
  Const ForReading = 1
  Dim fso
  Set fso = Server.CreateObject("Scripting.FilesystemObject")
  Dim ts
  Set ts = fso.OpenTextFile(Server.MapPath(strFilename), ForReading)
  getMappedFileAsString = ts.ReadAll
  ts.close
  Set ts = nothing
  Set fso = Nothing
End Function

Set fsObject = Server.CreateObject("Scripting.FileSystemObject")
Dim strInclude
If fsObject.FileExists(Server.MapPath("templates/" & x & "/header.asp)) = true then
	strInclude = getMappedFileAsString("templates/" & x & "/header.asp)
	Execute strInclude
End if
set fsObject = nothing
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top