Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 8 of 8
  1. #1
    Regular Coder
    Join Date
    Jun 2002
    Posts
    358
    Thanks
    2
    Thanked 0 Times in 0 Posts

    How to make a dynamic Incude file instead of hardcode it.

    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?


    Code:
    <!--#INCLUDE FILE = "../config.asp"-->
    <!--#INCLUDE FILE = "../class/User.asp"-->
    <!--#INCLUDE FILE = "../includes/functions.asp"-->
    <!--#INCLUDE FILE = "../lib/lib.asp"-->
    
    if abc = "" then
       strIncludeFile="login.asp"
    else
       strIncludeFile="welcome.asp"
    end if
    
    <!--#INCLUDE FILE = "../template/template.asp"-->
    will it be a problem if i use Sever.Execute?

    in the template.asp:

    Code:
    <table width="100%" border="0" cellspacing="3" cellpadding="0">
      <tr>
        <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 
    			Server.Execute(strIncludeFile)
    		else 
    			Response.Write "Missing/Incomplete "& strIncludeFile &" in your controller."
    		end if
    	%>
    	</td>
      </tr>
    </table>
    Last edited by NinjaTurtle; 09-21-2005 at 09:01 AM.
    Thanks.
    =====================================================
    From NinjaTurtle
    ++http://ohmygoh.blogspot.com|http://technology.ohmygoh.com++

  • #2
    Senior Coder NancyJ's Avatar
    Join Date
    Feb 2005
    Location
    Bradford, UK
    Posts
    3,172
    Thanks
    19
    Thanked 65 Times in 64 Posts

  • #3
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,043
    Thanks
    0
    Thanked 251 Times in 247 Posts
    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.

  • #4
    Regular Coder
    Join Date
    Jun 2002
    Posts
    358
    Thanks
    2
    Thanked 0 Times in 0 Posts
    hhhmmm... My include files all is asp file with server side code....
    Last edited by NinjaTurtle; 09-21-2005 at 02:02 PM.
    Thanks.
    =====================================================
    From NinjaTurtle
    ++http://ohmygoh.blogspot.com|http://technology.ohmygoh.com++

  • #5
    Regular Coder
    Join Date
    Sep 2004
    Posts
    152
    Thanks
    0
    Thanked 0 Times in 0 Posts
    @NinjaTurtle,
    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"-->

  • #6
    Regular Coder
    Join Date
    Jun 2002
    Posts
    358
    Thanks
    2
    Thanked 0 Times in 0 Posts
    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.
    Last edited by NinjaTurtle; 09-21-2005 at 03:20 PM.
    Thanks.
    =====================================================
    From NinjaTurtle
    ++http://ohmygoh.blogspot.com|http://technology.ohmygoh.com++

  • #7
    Regular Coder
    Join Date
    Jun 2002
    Posts
    358
    Thanks
    2
    Thanked 0 Times in 0 Posts
    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"-->
    or
    <!--#Include File="/<%=myprojectpath%>/class/User.asp"-->
    ????

    But i knew thats not working, just want to mention wahta i needed.
    Thanks.
    =====================================================
    From NinjaTurtle
    ++http://ohmygoh.blogspot.com|http://technology.ohmygoh.com++

  • #8
    Regular Coder
    Join Date
    Sep 2004
    Posts
    152
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •