Quantcast
Channel: How to get relative path from absolute path - Stack Overflow
Viewing all articles
Browse latest Browse all 25

Answer by Ray for How to get relative path from absolute path

$
0
0

If you are using .NET Core 2.0, Path.GetRelativePath() is available providing this specific functionality:

        var relativeTo = @"C:\Program Files\Dummy Folder\MyProgram";        var path = @"C:\Program Files\Dummy Folder\MyProgram\Data\datafile1.dat";        string relativePath = System.IO.Path.GetRelativePath(relativeTo, path);        System.Console.WriteLine(relativePath);        // output --> Data\datafile1.dat 

Otherwise, for .NET full framework (as of v4.7) recommend using one of the other suggested answers.


Viewing all articles
Browse latest Browse all 25

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>