AVM.DDP.MetaAvmProject.MakeRelativePath C# (CSharp) Method

MakeRelativePath() public static method

Creates a relative path from one file or folder to another.
public static MakeRelativePath ( string fromPath, string toPath ) : string
fromPath string Contains the directory that defines the start of the relative path.
toPath string Contains the path that defines the endpoint of the relative path.
return string
        public static string MakeRelativePath(string fromPath, string toPath)
        {
            Contract.Requires(string.IsNullOrEmpty(fromPath) == false);
            Contract.Requires(string.IsNullOrEmpty(toPath) == false);

            Uri fromUri = new Uri(Path.GetFullPath(fromPath));
            Uri toUri = new Uri(Path.GetFullPath(toPath));

            Uri relativeUri = fromUri.MakeRelativeUri(toUri);
            string relativePath = Uri.UnescapeDataString(relativeUri.ToString());
            if (relativePath.StartsWith("../") == false)
            {
                relativePath = relativePath.Substring(relativePath.IndexOf('/'));
                relativePath = "." + relativePath;
            }

            return relativePath.Replace('/', Path.DirectorySeparatorChar);
        }
    }