Author | Message | Time |
---|---|---|
tA-Kane | Using server-side includes (.ssi, .shtml), how do I include a file which is in the current file's parent folder? | June 19, 2003, 7:05 AM |
Grok | Three ways I can immediately think of: 1. If your server allows parent paths, which it shouldn't, use: [code]<!-- #include file="../navbar.asp" -->[/code] 2. If your server prevents parent-paths, use explicit path from root: [code]<!-- #include file="/shared/navbar.asp" -->[/code] 3. Or an alternative is to use code to solve the problem. Use server variables and functions to get your absolute path. If on IIS, use the FileSystemObject to GetParentPath and then build your include. [code]Dim fso, pathCurrent, pathParent, pathIncludeFile Set fso = Server.CreateObject("Scripting.FileSystemObject") pathCurrent = Request.ServerVariables("DOCUMENT_URI") pathParent = fso.GetParentFolderName(pathCurrent) pathIncludeFile = fso.BuildPath(pathParent, "navbar.asp") Response.Write "<!-- #include file=""" & pathIncludeFile & """ -->[/code] HTH, Grok. | June 19, 2003, 7:49 AM |
Eibro | I don't think that third method will work. Include files are inserted before scripts are executed. | June 19, 2003, 7:01 PM |
Hostile | Switch to JSP :p | June 20, 2003, 5:30 PM |
Grok | [quote author=Eibro link=board=22;threadid=1662;start=0#msg12646 date=1056049281] I don't think that third method will work. Include files are inserted before scripts are executed. [/quote] So write a script that creates a myinclude.inc containing the proper path. Server.Transfer back to yourself, so you are read again. This time, the include should have the correct path. | June 20, 2003, 6:34 PM |