[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now


Include File Path problems

Posted on 2005-04-08
Medium Priority
Last Modified: 2013-11-18
Hi all,

I am working on a menu that needs to be included in all the pages of my website.

At this time, the structure of my site is as follows:

Root: menu.asp, index.asp, header.asp etc....

Then, subfolders: let's say Folder1. And in Folder1 asp pages that include the header located in the root.

My header code (header.asp) is like this:

<table cellpadding="0" cellspacing="0" width="743" align="center" height="123">
     <td align="center" width="743" height="123" background="http://www.mysite.com/images/logo/logo.gif">
   <tr><td><!-- #include file = "menu.asp"--></td></tr>

I include the header in all of my pages like this at the top of each pages:

<body class="body">
  <table class="maintable" align="center">
      <tr width="740" height="120" >
          <td colspan="3"><!--#include file="Header.asp"--></td>


Now without the menu.asp include, everything works fine. The logo is included in each file since I'm using the absolute path to the image.

But my menu is only properly included in the index page. On any other subpages located in subfolders, the menu does not appear. I'm sure it's because the ../../ are screwed up because of the include, but is there anyway around this?

And maybe it's a javascript path problem. My menu.asp is like this:

<!-- menu script itself-->
<script language="JavaScript" src="menu.js"></script>
<!-- links are stored there -->
<script language="JavaScript" src="menu_items.js"></script>
<!-- styles structures -->
<script language="JavaScript" src="menu_tpl.js"></script>
<script language="JavaScript">
    new menu (MENU_ITEMS, MENU_POS);

thanks in advance!
Question by:ThePrince
  • 4
  • 2
  • 2
  • +2
LVL 18

Accepted Solution

SquareHead earned 900 total points
ID: 13736366
You may have better results with this:

<!--#include virtual="Header.asp"-->
<!--#include virtual="menu.asp"-->
LVL 18

Expert Comment

ID: 13736406
When you use "file" rather than "virtual", the path to the include is relative to where the included content ultimately displays...

So if you have files located at different levels, it's difficult to have includes calling other includes when you use "file" and not "virtual"...

Note that the folder that contains the include being called via "virtual" must actually be a virtual folder. But this is usually the case with your web root, so you should be ok.
LVL 13

Expert Comment

ID: 13736420
when you include file header.asp into myfile.asp in the subfoler

subfolder myfile.asp
root header.asp

header.asp and its contents become with the same level with myfile.asp on the sub folder

and it will look for the menu.js etc... in the subfolder directory

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

LVL 18

Expert Comment

ID: 13736421
If my first suggestion doesn't work, try adding an "Includes" folder in your root. Then try the following:

<!--#include virtual="Includes/Header.asp"-->
<!--#include virtual="Includes/menu.asp"-->

You may need to define a new virtual folder in IIS that points to the Includes folder.
LVL 13

Expert Comment

ID: 13736670
SquareHead's solution is better i think :)

 you may create a subfolder "menu"

and put the header files in it

root folder
   MENU (folder)
      etc ...

---- menu.asp ---
<script language="JavaScript" src="../menu/menu.js"></script>
<!-- links are stored there -->

also for images give the path like "../menu/"  upto one level then into menu folder

subfolder (subpage.asp)
 <!-- #include file="../menu/menu.asp" -->

root folder (index.asp)
<!-- #include file="menu/menu.asp" -->


Expert Comment

ID: 13736899
For javascripts and images you can force the browser to request the files from the root by placing a / at the start of the filename or path.

<script language="JavaScript" src="/menu/menu.js"></script>
<td align="center" width="743" height="123" background="/images/logo/logo.gif">

I'm pretty sure this works for INCLUDE files too so try

 <!-- #include file="/menu/menu.asp" -->

LVL 14

Expert Comment

ID: 13742845
Things I would change to Garve's response...

language= is deprecated for client-side javascript, use type= instead.
<script type="text/javascript" src="/menu/menu.js"></script>

See deprecate:

include 'file' cannot start at root using / but include 'virtual' can.
<!--#include virtual="/menu/menu.asp"-->

However I agree with his approach and do this explicitly and never have session issues as you're experiencing.
LVL 18

Expert Comment

ID: 15331595
@ThePrince -- any update on this?

Expert Comment

ID: 15525316
No comment has been added to this question in more than 21 days, so it is now classified as abandoned..
I will leave the following recommendation for this question in the Cleanup topic area:
Split: SquareHead & nurbek & Garve

Any objections should be posted here in the next 4 days. After that time, the question will be closed.

EE Cleanup Volunteer
LVL 14

Expert Comment

ID: 15536722

If you use Garve's suggestion, you'll get an error:

Active Server Pages error 'ASP 0130'

Invalid File attribute

/menu/menu.asp, line #

File attribute '/menu/menu.asp' cannot start with forward slash or back slash.

However, putting everything in the menu folder is the best idea to keep everything together and use VIRTUAL to access it.

There is never a reason to parent paths unless your paths are so long that it would truncate do to the limit of the URL.  Also, parent paths should be disabled for security reasons.

I don't know why you left me out of the split but I would split between Garve any myself.  He had the right idea, just the wrong syntax.

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Most of the sites are being standardized with W3C Web Standards. W3C provides lot of web standard services to the web. They have the web specification, process and documentation for all the web standards. You can apply HTML, CSS and Accessibility st…
I will show you how to create a ASP.NET Captcha control without using any HTTP HANDELRS or what so ever. you can easily plug it into your web pages. For Example a = 2 + 3 (where 2 and 3 are 2 random numbers) Session("Answer") = 5 then we…
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
The viewer will the learn the benefit of plain text editors and code an HTML5 based template for use in further tutorials.
Suggested Courses

872 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question