FilePathAbsoluteToRelativePath Method

This helper method can be used to convert an absolute path to one that is relative to the given base path.

Definition

Namespace: SandcastleBuilder.Utils
Assembly: SandcastleBuilder.Utils (in SandcastleBuilder.Utils.dll) Version: 2024.12.21.0
public static string AbsoluteToRelativePath(
	string basePath,
	string absolutePath
)

Parameters

basePath  String
The base path
absolutePath  String
An absolute path

Return Value

String
A path to the given absolute path that is relative to the given base path

Remarks

If the base path is null or empty, the current working folder is used.

Example

C#
string basePath = @"E:\DotNet\CS\TestProject\Source";
string absolutePath = @"E:\DotNet\CS\TestProject\Doc\Help.html";

string relativePath = FilePath.AbsoluteToRelativePath(basePath,
    absolutePath);

Console.WriteLine(relativePath);

// Results in: ..\Doc\Help.html

See Also