Answers for "how to get relative path in c#"

C#
0

how to get relative path in c#

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)
    );
Posted by: Guest on September-30-2020

C# Answers by Framework

Browse Popular Code Answers by Language