0 out of 1 rated this helpful - Rate this topic

Uri Constructor (Uri, String)

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

Namespace:  System
Assembly:  System (in System.dll)
public Uri(
	Uri baseUri,
	string relativeUri
)

Parameters

baseUri
Type: System.Uri

The base URI.

relativeUri
Type: System.String

The relative URI to add to the base URI.

ExceptionCondition
ArgumentNullException

uriString is null.

ArgumentOutOfRangeException

baseUri is not an absolute Uri instance.

UriFormatException

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 Uri instance by combining the baseUri and the relativeUri. If relativeUri is an absolute URI (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.

The following example creates a new instance of the Uri class by combining the relative URIs http://www.contoso.com and catalog/showew.htm to form the absolute URI http://www.contoso.com/catalog/shownew.htm.

Uri baseUri = new Uri("http://www.contoso.com");
 Uri myUri = new Uri(baseUri, "catalog/shownew.htm");

Console.WriteLine(myUri.ToString());
	Uri* baseUri = new Uri("http://www.contoso.com");
	Uri* myUri = new Uri(baseUri, "catalog/shownew.htm");

	Console::WriteLine(myUri->ToString());

Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98, Windows CE, Windows Mobile for Smartphone, Windows Mobile for Pocket PC, Xbox 360, Zune

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

.NET Framework

Supported in: 3.5, 3.0, 2.0, 1.1, 1.0

.NET Compact Framework

Supported in: 3.5, 2.0, 1.0

XNA Framework

Supported in: 3.0, 2.0, 1.0
Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft. All rights reserved.