Uri Constructor (Uri, Uri)

Initializes a new instance of the Uri class based on the combination of a specified base Uri instance and a relative Uri instance.

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

'Declaration
Public Sub New ( _
	baseUri As Uri, _
	relativeUri As Uri _
)

Parameters

baseUri
Type: System.Uri

An absolute Uri that is the base for the new Uri instance.

relativeUri
Type: System.Uri

A relative Uri instance that is combined with baseUri.

ExceptionCondition
ArgumentException

baseUri is not an absolute Uri instance.

ArgumentNullException

baseUri is Nothing.

ArgumentOutOfRangeException

baseUri is not an absolute Uri instance.

UriFormatException
NoteNote

In the .NET for Windows Store apps or the Portable Class Library, catch the base class exception, FormatException, instead.

The URI formed by combining baseUri and relativeUri is empty or contains only spaces.

-or-

The scheme specified in the URI formed by combining baseUri and relativeUri is not valid.

-or-

The URI formed by combining baseUri and relativeUri contains too many slashes.

-or-

The password specified in the URI formed by combining baseUri and relativeUri is not valid.

-or-

The host name specified in the URI formed by combining baseUri and relativeUri is not valid.

-or-

The file name specified in the URI formed by combining baseUri and relativeUri is not valid.

-or-

The user name specified in the URI formed by combining baseUri and relativeUri is not valid.

-or-

The host or authority name specified in the URI formed by combining baseUri and relativeUri cannot be terminated by backslashes.

-or-

The port number specified in the URI formed by combining baseUri and relativeUri is not valid or cannot be parsed.

-or-

The length of the URI formed by combining baseUri and relativeUri exceeds 65519 characters.

-or-

The length of the scheme specified in the URI formed by combining baseUri and relativeUri exceeds 1023 characters.

-or-

There is an invalid character sequence in the URI formed by combining baseUri and relativeUri.

-or-

The MS-DOS path specified in uriString must start with c:\\.

This constructor creates a new Uri instance by combining an absolute Uri instance, baseUri, with a relative Uri instance, relativeUri. If relativeUri is an absolute Uri instance (containing a scheme, host name, and optionally a port number), the Uri instance is created using only relativeUri.

This constructor does not ensure that the Uri refers to an accessible resource.

This example creates an absolute Uri instance, absoluteUri, and a relative Uri instance, relativeUri. A new Uri instance, combinedUri, is then created from these two instances.

    ' Create an absolute Uri from a string. 
    Dim absoluteUri As New Uri("http://www.contoso.com/")

    ' Create a relative Uri from a string.  allowRelative = true to allow for  
    ' creating a relative Uri. 
    Dim relativeUri As New Uri("/catalog/shownew.htm?date=today")

    ' Check whether the new Uri is absolute or relative. 
    If Not relativeUri.IsAbsoluteUri Then
        Console.WriteLine("{0} is a relative Uri.", relativeUri)
    End If  
    ' Create a new Uri from an absolute Uri and a relative Uri. 
    Dim combinedUri As New Uri(absoluteUri, relativeUri)
    Console.WriteLine(combinedUri.AbsoluteUri)

End Sub 'SampleConstructor

.NET Framework

Supported in: 4.5.2, 4.5.1, 4.5, 4, 3.5, 3.0, 2.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Portable Class Library

Supported in: Portable Class Library

.NET for Windows Store apps

Supported in: Windows 8

.NET for Windows Phone apps

Supported in: Windows Phone 8.1, Windows Phone 8, Silverlight 8.1

Windows Phone 8.1, Windows Phone 8, Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

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

Was this page helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft