| 1 | using System; |
| 2 | using System.IO; |
| 3 | |
| 4 | public static class PathHelper |
| 5 | { |
| 6 | public static string MakeRelativePath(string fromPath, string toPath) |
| 7 | { |
| 8 | var fromUri = new Uri(Path.GetFullPath(fromPath)); |
| 9 | var toUri = new Uri(Path.GetFullPath(toPath)); |
| 10 | |
| 11 | if (fromUri.Scheme != toUri.Scheme) |
| 12 | { |
| 13 | return toPath; |
| 14 | } |
| 15 | |
| 16 | var relativeUri = fromUri.MakeRelativeUri(toUri); |
| 17 | var relativePath = Uri.UnescapeDataString(relativeUri.ToString()); |
| 18 | |
| 19 | if (toUri.Scheme.Equals("file", StringComparison.InvariantCultureIgnoreCase)) |
| 20 | { |
| 21 | relativePath = relativePath.Replace(Path.AltDirectorySeparatorChar, Path.DirectorySeparatorChar); |
| 22 | } |
| 23 | |
| 24 | return relativePath; |
| 25 | } |
| 26 | } |