This documentation is archived and is not being maintained.

VirtualPathUtility::MakeRelative Method

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

Namespace:  System.Web
Assembly:  System.Web (in System.Web.dll)

public:
static String^ MakeRelative(
	String^ fromPath, 
	String^ toPath
)

Parameters

fromPath
Type: System::String

The starting virtual path to return the relative virtual path from.

toPath
Type: System::String

The ending virtual path to return the relative virtual path to.

Return Value

Type: System::String
The relative virtual path from fromPath to toPath.

ExceptionCondition
ArgumentException

fromPath is not rooted.

- or -

toPath is not rooted.

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 MakeRelative method returns "../directory2/file2.aspx".

Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

.NET Framework

Supported in: 3.5, 3.0, 2.0
Show: