System.IO.Path.GetRelativePath C# (CSharp) Méthode

GetRelativePath() public static méthode

Create a relative path from one path to another. Paths will be resolved before calculating the difference. Default path comparison for the active platform will be used (OrdinalIgnoreCase for Windows or Mac, Ordinal for Unix).
Thrown if or is null or an empty string.
public static GetRelativePath ( string relativeTo, string path ) : string
relativeTo string The source path the output should be relative to. This path is always considered to be a directory.
path string The destination path.
Résultat string
        public static string GetRelativePath(string relativeTo, string path)
        {
            return GetRelativePath(relativeTo, path, StringComparison);
        }

Same methods

Path::GetRelativePath ( string relativeTo, string path, StringComparison comparisonType ) : string

Usage Example

Exemple #1
0
        private static string GetPath(bool makeAbsolute, string filePath, string absBasePath)
        {
            string absFilePath = Path.IsPathRooted(filePath)
                ? filePath
                : new FileInfo(Path.Combine(absBasePath, filePath)).FullName;

            return(makeAbsolute
                ? absFilePath
                : Path.GetRelativePath(absBasePath, absFilePath));
        }
All Usage Examples Of System.IO.Path::GetRelativePath