📜  如何在c#代码示例中获取相对路径

📅  最后修改于: 2022-03-11 14:49:14.459000             🧑  作者: Mango

代码示例1
Uri file = new Uri(@"c:\foo\bar\blop\blap.txt");
// Must end in a slash to indicate folder
Uri folder = new Uri(@"c:\foo\bar\");
string relativePath = 
Uri.UnescapeDataString(
    folder.MakeRelativeUri(file)
        .ToString()
        .Replace('/', Path.DirectorySeparatorChar)
    );