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 bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Path for #Include File 1

Status
Not open for further replies.

xenology

Programmer
May 22, 2002
51
US
I have myFunctions.asp in the root of folder. Several pages need to include this file. Some of the pages are in the root directory, some are in sub-directories two or three levels deep.

<!--#include file=&quot;myFunctions.asp&quot;-->
and
<!--#include file=&quot;..\myFunctions.asp&quot;-->
and
<!--#include file=&quot;..\..\myFunctions.asp&quot;-->

all work. However, because some pages get moved around to other directories, the &quot;..\&quot; has to be updated.

Question: Is there some magical way of saying:
<!--#include file=currentwebsiteroot + &quot;myFunctions.asp&quot;-->
that could be put on every needed page regardless of the directory they are in?
 
Have you tried

<!-- #include Virtual=&quot;/myFunctions.asp&quot; -->

?
 
After I figured out that I had to create a Virtual Directory on my web server (there was already one there called Scripts). I put myFunctions.asp in that directory (seperate from my web app directory) and then referenced it as
<!-- #include virtual=&quot;/scripts/myFunctions.asp&quot; -->
and it worked perfectly from all subdirectories.

THANKS MMCGON !!!!
 
Actually what you need to have in mind for <!--#include file=&quot;filepath&quot;--> is
1.that you can use absolute and virtual paths to files
2.default path values are virtual if not specified
3.the signs used on the filepath
&quot;/&quot; - means that your path starts from root directory wich on a web server it's it's default path inetpub/ &quot;/test&quot; -> &quot;inetpub/ &quot;&quot;(nothing) - means that your path starts from curent application directory
&quot;test&quot; -> &quot;inetpub/ &quot;../&quot; - means that your starting directory will be the one level down in the directory structure
&quot;../test&quot; from your application directory (myapplication)-> &quot;inetpub/
So for your problem as you actually find out you need to have an directory that you can acess from all over the places, so you would need the &quot;/dirname&quot; to do that.

________
George, M
 
Think of the Virtual Directory as an alias name for the real directory, wherever it is. For example, if the directory with your include code is named MyScripts, then you must name the virtual directory differently, such as Scripts. When I created some a year or two ago, my version of IIS would not let them have the same names.
 
You don't have to have those scripts in a virtual directory. All <!-- #include virtual=&quot;directory/file.inc&quot; --> means is that the page will search for this file starting at the root directory and working to the subdirectory and so on. You could have a directory called &quot;includes in your root directory and no matter where your page is located you would just call that file as follows:

<!-- #include virtual=&quot;includes/file.inc&quot; -->
 
DaveGerard,
For a long time I never used virtual directories, but when I placed some ASP pages in subdirectories, not in the top-level default \inetpub\ directory, I couldn't see other subdirectories that had branched off from higher levels, you know, like &quot;cousin&quot; files. At the time only virtual directories let me do that. I think I'm using an older IIS version (3) as well, which may be a factor. While I may not have tried all the other suggestions listed here (I think I did?), it has worked for me and I won't fiddle with it for a while.
 
The same happened to me dbMark (IIS 5.0). I had the file in the root of the web folder and called it as include file = &quot;/file.inc&quot; and it always responded with file not found. When I placed it in the virtual and referenced it as such, it started working.
Thanks for everyone's help on this!

-xeno
 
If you use &quot;/name/file.inc&quot; in front of a path it means the root directory not the curent directory wich is &quot;./name/file.inc&quot; or just&quot;name/file.inc&quot; and as i sayed all includes are virtual.


________
George, M
 
Really? Explain this then...

Active Server Pages error 'ASP 0130'

Invalid File attribute

/login/LoginProcess.asp, line 1

File attribute '/connect.inc' cannot start with forward slash or back slash.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top