Mono Class Library: System.Uri Overview | Members

System.Uri.GetLeftPart Method

Returns the specified portion of the URI represented by the current instance. [Edit]

public string GetLeftPart (UriPartial part)

Parameters

part
A UriPartial value that specifies the component to return. [Edit]

Returns

A string containing all components up to the specified portion of the URI, or string.Empty if the current instance does not contain the component identified by part . [Edit]

Exceptions

TypeReason
ArgumentExceptionThe part parameter is not a valid UriPartial value. [Edit]

Remarks

The Uri.GetLeftPart(UriPartial) method returns a string containing the URI components starting with the left-most component of the URI and ending with the component specified by part . The returned string does not include fragment or query information.

Uri.GetLeftPart(UriPartial) includes delimiters as follows:

[Edit]

Example

The following example demonstrates the Uri.GetLeftPart(UriPartial) method.

C# Example
using System;

public class UriTest {
  public static void Main() {
    string[] myUri  = {
            "http://www.contoso.com/index.htm",
            "http:www.contoso.com/index.htm#mark",
                    "mailto:user@contoso.com?subject=uri",
                    "nntp://news.contoso.com/123456@contoso.com"
    };
    foreach (string s in myUri) {
      Uri aUri = new Uri(s);
      Console.WriteLine("URI: {0}", aUri.ToString());
      Console.WriteLine("Scheme: {0}",aUri.GetLeftPart(UriPartial.Scheme));
      Console.WriteLine("Authority: {0}",aUri.GetLeftPart(UriPartial.Authority));
      Console.WriteLine("Path: {0}",aUri.GetLeftPart(UriPartial.Path));
    }  
  }
}

The output is

URI: http://www.contoso.com/index.htm
Scheme: http://
Authority: http://www.contoso.com
Path: http://www.contoso.com/index.htm
URI: http://www.contoso.com/index.htm#mark
Scheme: http://
Authority: http://www.contoso.com
Path: http://www.contoso.com/index.htm
URI: mailto:user@contoso.com?subject=uri
Scheme: mailto:
Authority:
Path: mailto:user@contoso.com
URI: nntp://news.contoso.com/123456@contoso.com
Scheme: nntp://
Authority: nntp://news.contoso.com
Path: nntp://news.contoso.com/123456@contoso.com

Requirements

Namespace: System
Assembly: System (in System.dll)
Assembly Versions: 1.0.5000.0, 2.0.0.0