|
Util Object |
|
See Also: |
The Util.BuildRelativePath() method computes a relative path from one path to another path.
VBScript:
JScript:
| Util | The Util object. |
| strPathFrom | The starting path. |
| strPathTo | The destination path. |
| bPathFromIsDir | Optional. Specify True if strPathFrom is known to be
a directory. The default value is False.
True: strPathFrom is a directory. False: strPathFrom is a directory only if it ends with a slash. Otherwise it is a file. |
| strRelPath | Combining strPathFrom with this value equals strPathTo. |
The return value strRelPath uses the same type of slashes (forward slashes, or backslashes) as strPathTo.
Util.BuildRelativePath() builds the relative path by finding identical path segments at the beginning of both strPathFrom and strPathTo. The comparison of path segments is case-insensitive.
Util.BuildRelativePath() assumes that strPathFrom and strPathTo are on the same volume. This allows
combination of partial paths, so that
Util.BuildRelativePath("subdir1\", "subdir2\")
returns "..\subdir2\". If strPathFrom and strPathTo are full paths on different drives, you may receive an invalid return value. We recommend that you ensure that strPathFrom and strPathTo are on the same drive before calling Util.BuildRelativePath().
Following are some example result sets for Util.BuildRelativePath().
| strPathFrom | "\prj\web\site\content\products\" |
| strPathTo | "/prj/web/site/drop/products/default.htm" |
| strRelPath | "../../drop/products/default.htm" |
| strPathFrom | "\prj\web\site\content\products" |
| strPathTo | "/prj/web/site/drop/products/default.htm" | bPathFromIsDir | True |
| strRelPath | "../../drop/products/default.htm" |
| strPathFrom | "\prj\web\site\content\products" |
| strPathTo | "/prj/web/site/drop/products/default.htm" | bPathFromIsDir | False |
| strRelPath | "../drop/products/default.htm" |
| strPathFrom | "c:\Program Files\APGen\bin\APGen.exe" |
| strPathTo | "c:\Util\apg scripts\script.apg" |
| strRelPath | "..\..\..\Util\apg scripts\script.apg" |
This example computes the relative path to an image file for a HTML IMG tag. The relative path is computed using Output.Path as strPathFrom, which will make the image viewable in the resulting web page.
<%#
...
Dim sImgPath
sImgPath = "c:/prj/web/drop/img/logo.gif"
#%>
<IMG src="<%# =Util.BuildRelativePath(Output.Path, sImgPath) #%>" >
...