C# Uri MakeRelative

Description

Uri MakeRelative determines the difference between two Uri instances.

Syntax

Uri.MakeRelative has the following syntax.


[ObsoleteAttribute("The method has been deprecated. Please use MakeRelativeUri(Uri uri). http://go.microsoft.com/fwlink/?linkid=14202")]
public string MakeRelative(
  Uri toUri
)

Parameters

Uri.MakeRelative has the following parameters.

  • toUri - The URI to compare to the current URI.

Returns

Uri.MakeRelative method returns If the hostname and scheme of this URI instance and toUri are the same, then this method returns a String that represents a relative URI that, when appended to the current URI instance, yields the toUri parameter. If the hostname or scheme is different, then this method returns a String that represents the toUri parameter.

Example

The following example creates 2 Uri instances. The difference in the path information is written to the console.


/*ww w . java  2  s.  co m*/
using System;
public class MainClass{
  public static void Main(String[] argv){  
    // Create a base Uri.
    Uri address1 = new Uri("http://www.java2s.com/");
    
    // Create a new Uri from a string.
    Uri address2 = new Uri("http://www.java2s.com/index.htm?date=today"); 
    
    // Determine the relative Uri.  
    Console.WriteLine("The difference is {0}", address1.MakeRelativeUri(address2));

  }
}
    

The code above generates the following result.





















Home »
  C# Tutorial »
    System »




Array
BitConverter
Boolean
Byte
Char
Console
ConsoleKeyInfo
Convert
DateTime
DateTimeOffset
Decimal
Double
Enum
Environment
Exception
Guid
Int16
Int32
Int64
Math
OperatingSystem
Random
SByte
Single
String
StringComparer
TimeSpan
TimeZone
TimeZoneInfo
Tuple
Tuple
Tuple
Type
UInt16
UInt32
UInt64
Uri
Version