Calculating the path relative to some root- the inverse of Path.Combine

Viewed 6441

Is there a reliable way to calculate the inverse of Path.Combine()?

Path.Combine("c:\folder", "subdirectory\something.txt") might return something like "c:\folder\subdirectory\something.text". What I want is the inverse, a function where Path.GetRelativeUrl("c:\folder", "c:\folder\subdirectory\something.text") would return something like ""subdirectory\something.txt".

One solution is to do string comparisons and trim the roots, but this would not work when the same path is expressed in different ways (use of ".." or "~1" in path expression).

4 Answers
Related