This topic has not yet been rated - Rate this topic

Uri Constructor (Uri, String)

.NET Framework 1.1

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

[Visual Basic]
Public Sub New( _
   ByVal baseUri As Uri, _
   ByVal relativeUri As String _
)
[C#]
public Uri(
   Uri baseUri,
 string relativeUri
);
[C++]
public: Uri(
   Uri* baseUri,
 String* relativeUri
);
[JScript]
public function Uri(
   baseUri : Uri,
 relativeUri : String
);

Parameters

baseUri
The base URI.
relativeUri
The relative URI to add to the base URI.

Exceptions

Exception Type Condition
ArgumentNullException uriString is a null reference (Nothing in Visual Basic).
UriFormatException The URI formed by combining baseUri and relativeUri is empty.

-or-

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

-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 invalid.

-or-

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

-or-

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

Remarks

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

Example

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 .

[Visual Basic] 
Dim baseUri As New Uri("http://www.contoso.com")
Dim myUri As New Uri(baseUri, "catalog/shownew.htm")

Console.WriteLine(myUri.ToString())


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

Console.WriteLine(myUri.ToString());
   

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

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

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

Requirements

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family, .NET Compact Framework, Common Language Infrastructure (CLI) Standard

See Also

Uri Class | Uri Members | System Namespace | Uri Constructor Overload List

Did you find this helpful?
(1500 characters remaining)