Path.GetRelativePath(String, String) Method

Definition

Returns a relative path from one path to another.

public:
 static System::String ^ GetRelativePath(System::String ^ relativeTo, System::String ^ path);
public static string GetRelativePath (string relativeTo, string path);
static member GetRelativePath : string * string -> string
Public Shared Function GetRelativePath (relativeTo As String, path As String) As String

Parameters

relativeTo
String

The source path the result should be relative to. This path is always considered to be a directory.

path
String

The destination path.

Returns

String

The relative path, or path if the paths don't share the same root.

Exceptions

relativeTo or path is null.

relativeTo or path is effectively empty.

Remarks

Paths are resolved by calling the GetFullPath method before calculating the difference. The method uses the default file path comparison for the current platform (StringComparison.OrdinalIgnoreCase for Windows and MacOs, StringComparison.Ordinal for Linux.

Applies to

See also