Q:

To relative path from base absolute

I have an absolute folder path and files path like following:
C:\BaseDir - base folder
C:\BaseDir\sub\123.txt - path to file that is located in base folder (but maybe also with some subfolders)
Another example of file path: C:\BaseDir\file.docx or C:\BaseDir\sub\sub1\file.exe
I need to convert pathes to files from absolute to relative based on the base folder. Results should look like following:
sub\123.txt ; file.docx ; sub\sub1\file.exe
Please note, that I don't want BaseDir in path. Solution should also work with network folders(\\Server1\BaseDir\file.docx or \\172.31.1.60\BaseDir\sub\123.txt).
Are there any built in classes that do this?

A:

Credits goes do this post: Absolute to Relative path
public static string AbsoluteToRelativePath(string pathToFile, string referencePath)
{
    var fileUri = new Uri(pathToFile);
    var referenceUri = new Uri(referencePath);
    return referenceUri.MakeRelativeUri(fileUri).ToString();
}

Now you can use this like
var result = AbsoluteToRelativePath(@"C:\dir\path\to\file.txt", @"C:\dir\");

