System.Web.VirtualPathUtility.MakeRelative Method

Returns the relative virtual path from one virtual path containing the root operator (the tilde [~]) to another.

Syntax

public static string MakeRelative (string fromPath, string toPath)

Parameters

fromPath
The starting virtual path to return the relative virtual path from.
toPath
The ending virtual path to return the relative virtual path to.

Returns

The relative virtual path from fromPath to toPath.

Remarks

If the fromPath and toPath parameters are not rooted; that is, they do not equal the root operator (the tilde [~]), do not start with a tilde (~), such as a tilde and a slash mark (~/) or a tilde and a double backslash (~//), or do not start with a slash mark (/), an ArgumentException exception is thrown.

Query string parameters and HTML anchors that are used in the URI are not used in determining the relative path.

If fromPath is "/directory1/file1.aspx" and toPath is "/directory2/file2.aspx", the VirtualPathUtility.MakeRelative(string, string) method returns "../directory2/file2.aspx".

Requirements

Namespace: System.Web
Assembly: System.Web (in System.Web.dll)
Assembly Versions: 2.0.0.0
Since: .NET 2.0