25.2.10

Different Types of Paths



There are two options

* Absolute Paths
Link uses the full URL of an object or page. While you can use it within your own site, there is rarely ever a need to do so.

* Relative Paths
Any time you need to send a visitor to another page within your site or include an object from your site (like an image) on one of your pages a relative link will work just fine.

- Document Relative
It is the most widely used type of relative linking, and for good reason. They can easily move up and down your site's hierarchy, in and out of directories (folders) without a hitch.
eg:OPEN img src="images/title.gif" CLOSE
See the above image instead of the products page being in the same directory as the home page it is actually located in a subdirectory. You still need to include the images in the page but the page is in a directory (folder) deeper than the root level of your site.
As you can see you need to move up and out of the products directory in order to get to the images folder in order to access the needed images
eg:OPEN img src="../images/title.gif" CLOSE

- Root Relative
A site root-relative path describes the location of the destination file by describing the route the browser must take from the Web site's root folder (top level in the folder structure).
eg:OPEN img src="/html/images/image1.gif" CLOSE
"/" denotes root directory
You just need to use the System.Web.VirtualPathUtility.ToAbsolute("~") method to convert the ~ to the ApplicationPath.So, if your file is located at "~/common/images/spacer.gif" and you need to specify this path in a client tag like OPEN img CLOSE, ASP.NET would not allow you to use this path unless you use a Server Control like OPEN asp:Image CLOSE.
To continue using the client tag you can use:
OPEN img src="OPEN %=System.Web.VirtualPathUtility.ToAbsolute("~")%CLOSE /common/images/spacer.gif" / CLOSE
and this would be resolved to "/MyApplication/common/images/spacer.gif" where the first forward slash (/) stands for the WebSite root. Thus, the tilde "~" is effectively resolved to "/MyApplication"
Alternatively, Control.ResolveClientUrl can be used. For example
OPEN img src='<%= ResolveClientUrl("~/common/images/spacer.gif")%>' / CLOSE