System.Uri.MakeRelative C# (CSharp) Method

MakeRelative() private method

private MakeRelative ( Uri toUri ) : string
toUri Uri
return string
        public string MakeRelative(Uri toUri)
        {
            if (toUri == null)
                throw new ArgumentNullException(nameof(toUri));

            if (IsNotAbsoluteUri || toUri.IsNotAbsoluteUri)
                throw new InvalidOperationException(SR.net_uri_NotAbsolute);

            if ((Scheme == toUri.Scheme) && (Host == toUri.Host) && (Port == toUri.Port))
                return PathDifference(AbsolutePath, toUri.AbsolutePath, !IsUncOrDosPath);

            return toUri.ToString();
        }

Usage Example

Example #1
0
        //
        // MakeRelative
        //
        //  Return a relative path which when applied to <path1> with a Combine()
        //  results in <path2>
        //
        // Inputs:
        //  <argument>  path1
        //  <argument>  path2
        //      Paths for which we calculate the relative difference
        //
        //  <argument>  compareCase
        //      False if we should consider characters that differ only in case
        //      to be equal
        //
        // Outputs:
        //  Nothing
        //
        // Assumes:
        //  Nothing
        //
        // Returns:
        //  the relative path difference which when applied to <path1> using
        //  Combine(), results in <path2>
        //
        // Throws:
        //  Nothing
        //

        internal static string MakeRelative(string path1, string path2, bool compareCase) {

            Uri u1 = new Uri(path1);
            Uri u2 = new Uri(path2);

            //return PathDifference(path1, path2, compareCase);
            return u1.MakeRelative(u2);
        }
All Usage Examples Of System.Uri::MakeRelative