Click to Rate and Give Feedback
MSDN
MSDN Library
.NET Development
Previous Versions
.NET Framework 2.0
System
Uri Class
Uri Methods
 GetLeftPart Method

  Switch on low bandwidth view
This page is specific to
Microsoft Visual Studio 2005/.NET Framework 2.0

Other versions are also available for the following:
.NET Framework Class Library
Uri.GetLeftPart Method

Returns the specified portion of a Uri instance.

Namespace: System
Assembly: System (in system.dll)

Visual Basic (Declaration)
Public Function GetLeftPart ( _
    part As UriPartial _
) As String
Visual Basic (Usage)
Dim instance As Uri
Dim part As UriPartial
Dim returnValue As String

returnValue = instance.GetLeftPart(part)
C#
public string GetLeftPart (
    UriPartial part
)
C++
public:
String^ GetLeftPart (
    UriPartial part
)
J#
public String GetLeftPart (
    UriPartial part
)
JScript
public function GetLeftPart (
    part : UriPartial
) : String

Parameters

part

One of the UriPartial values that specifies the end of the URI portion to return.

Return Value

A String that contains the specified portion of the Uri instance.
Exception typeCondition

InvalidOperationException

The current Uri instance is not an absolute instance.

ArgumentException

The specified part is not valid.

The GetLeftPart method returns a string containing the leftmost portion of the URI string, ending with the portion specified by part.

GetLeftPart includes delimiters in the following cases:

  • Scheme includes the scheme delimiter.

  • Authority does not include the path delimiter.

  • Path includes any delimiters in the original URI up to the query or fragment delimiter.

  • Query includes the Path, plus the query and its delimiter.

The following examples show a URI and the results of calling GetLeftPart with Scheme, Authority, Path, or Query.

URI

Scheme

Authority

Path

Query

http://www.contoso.com/index.htm?date=today

http://

http://www.contoso.com

http://www.contoso.com/index.htm

http://www.contoso.com/index.htm?date=today

http://www.contoso.com/index.htm#main

http://

http://www.contoso.com

http://www.contoso.com/index.htm

http://www.contoso.com/index.htm

mailto:user@contoso.com?subject=uri

mailto:

mailto:user@contoso.com

mailto:user@contoso.com?subject=uri

<none>

nntp://news.contoso.com/123456@contoso.com

nntp://

nntp://news.contoso.com

nntp://news.contoso.com/123456@contoso.com

nntp://news.contoso.com/123456@contoso.com

news:123456@contoso.com

news:

news:123456@contoso.com

news:123456@contoso.com

<none>

file://server/filename.ext

file://

file://server

file://server/filename.ext

file://server/filename.ext

The following example creates a Uri instance and writes the path to the console.

Visual Basic
' Create Uri
Dim uriAddress As New Uri("http://www.contoso.com/index.htm#search")
Console.WriteLine(uriAddress.Fragment)
Console.WriteLine("Uri {0} the default port ", IIf(uriAddress.IsDefaultPort, "uses", "does not use")) 'TODO: For performance reasons this should be changed to nested IF statements

Console.WriteLine("The path of this Uri is {0}", uriAddress.GetLeftPart(UriPartial.Path))
Console.WriteLine("Hash code {0}", uriAddress.GetHashCode())
C#
// Create Uri
Uri uriAddress = new Uri("http://www.contoso.com/index.htm#search");
Console.WriteLine(uriAddress.Fragment);
Console.WriteLine("Uri {0} the default port ", uriAddress.IsDefaultPort ? "uses" : "does not use");
 
Console.WriteLine("The path of this Uri is {0}", uriAddress.GetLeftPart(UriPartial.Path));
Console.WriteLine("Hash code {0}", uriAddress.GetHashCode());

Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.

.NET Framework

Supported in: 2.0, 1.1, 1.0

.NET Compact Framework

Supported in: 2.0, 1.0
Tags What's this?: Add a tag
Community Content   What is Community Content?
Add new content RSS  Annotations
Processing
© 2009 Microsoft Corporation. All rights reserved. Terms of Use  |  Trademarks  |  Privacy Statement
Page view tracker