View Full Version : How to make a dynamic Incude file instead of hardcode it.

09-21-2005, 08:57 AM
i have a problem, in side the config.asp, i set a value :
strPath = "/myproject/"

i know that i cant set like this :
"<!--#INCLUDE FILE = "<%=strPath%>/class/User.asp"-->" for the Include file. or Even <!--#INCLUDE Virtual= "/class/User.asp"-->

Because of my project is quit big scale, many folders and Subfolders, may have sub- sub folders in future(not sure yet) so instead of i have to put "../" or "../../" any otherways of making it more flexible?

<!--#INCLUDE FILE = "../config.asp"-->
<!--#INCLUDE FILE = "../class/User.asp"-->
<!--#INCLUDE FILE = "../includes/functions.asp"-->
<!--#INCLUDE FILE = "../lib/lib.asp"-->

if abc = "" then
end if

<!--#INCLUDE FILE = "../template/template.asp"-->

will it be a problem if i use Sever.Execute?

in the template.asp:

<table width="100%" border="0" cellspacing="3" cellpadding="0">
<td width="19%" valign="top"><!--#INCLUDE FILE = "leftnav.asp"--></td>
<td width="81%">
set objFso = CreateObject("Scripting.FileSystemObject")

if objFso.FileExists (Server.MapPath(strIncludeFile)) then
Response.Write "Missing/Incomplete "& strIncludeFile &" in your controller."
end if

09-21-2005, 11:47 AM
Dynamic Includes (http://www.asp101.com/articles/michael/dynamicincludes/default.asp)

09-21-2005, 12:10 PM
Dynamic includes using FSO will only work if the include files only contain static HTML. If they contain server-side codes, it will not be executed. If you use Server.Transfer method, the codes will be executed.

09-21-2005, 01:16 PM
hhhmmm... My include files all is asp file with server side code....

09-21-2005, 03:09 PM
Why can't use a virtual include? If the path from the root of your website is "/myproject/class/User.asp", then you should be able to just put <!--#Include Virtual="/myproject/class/User.asp"-->

09-21-2005, 03:18 PM
i tried b4, but i dunno why it is not working. I use for my previous project b4, it works fine, but now i am using a new way of doing my project is to have a "controller" and a template(ASP, every page will share the same design, so that i no need to include so many top nave, left nav, bottom nav & ...)
May be is the Server.Execute problem (look at my 1st post) in the template file, when i tried to include a include file in the same include file(is not a cycle loop, with If statement) i wil lget error.

I wil ltried Server.Transfer with Virtual later. or may be i will post the error later.

09-21-2005, 08:02 PM
After i change the Server.Execute, the problem still occured, and the Virtual is working BUT this is not what i want, this is because when in the local server(development server) my directory will be "wwwroot/myproject/..." but if i put into LIVE server there is no folder called "/myproject". <!--#Include Virtual="/myproject/class/User.asp"--> it should be like this: <!--#Include Virtual="/class/User.asp"--> in the LIVE server. so i still cant make it dynamic, bcos i have to use the "../"

the main thing is how can i do like this or almost like that:
<!--#Include Virtual="/<%=myprojectpath%>/class/User.asp"-->
<!--#Include File="/<%=myprojectpath%>/class/User.asp"-->

But i knew thats not working, just want to mention wahta i needed.

09-22-2005, 03:17 PM
The problem is that #Include executes before any asp code. So if you point to a file that doesn't exist (i.e. <!--#Include Virtual="/myproject/.."-->), it's going to error out.

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum