Table of Contents

FilePath.AbsoluteToRelativePath Method

Definition

Namespace
Sandcastle.Core
Assembly
Sandcastle.Core.dll

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

public static string AbsoluteToRelativePath(string basePath, string absolutePath)

Parameters

basePath string

The base path

absolutePath string

An absolute path

Returns

string

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

Examples

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
Dim basePath As String = "E:\DotNet\CS\TestProject\Source"
Dim absolutePath As String = "E:\DotNet\CS\TestProject\Doc\Help.html"

Dim relativePath As String = _
    FilePath.AbsoluteToRelativePath(basePath, absolutePath);

Console.WriteLine(relativePath)

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

Remarks

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