Redigeeri

Jagamisviis:


Uri Constructors

Definition

Initializes a new instance of the Uri class.

Overloads

Uri(String)

Initializes a new instance of the Uri class with the specified URI.

Uri(SerializationInfo, StreamingContext)
Obsolete.

Initializes a new instance of the Uri class from the specified instances of the SerializationInfo and StreamingContext classes.

Uri(String, Boolean)
Obsolete.
Obsolete.
Obsolete.

Initializes a new instance of the Uri class with the specified URI, with explicit control of character escaping.

Uri(String, UriCreationOptions)

Initializes a new instance of the Uri class with the specified URI and additional UriCreationOptions.

Uri(String, UriKind)

Initializes a new instance of the Uri class with the specified URI. This constructor allows you to specify if the URI string is a relative URI, absolute URI, or is indeterminate.

Uri(Uri, String)

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

Uri(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.

Uri(Uri, String, Boolean)
Obsolete.
Obsolete.
Obsolete.

Initializes a new instance of the Uri class based on the specified base and relative URIs, with explicit control of character escaping.

Uri(String)

Source:
Uri.cs
Source:
Uri.cs
Source:
Uri.cs

Initializes a new instance of the Uri class with the specified URI.

public:
 Uri(System::String ^ uriString);
public Uri (string uriString);
new Uri : string -> Uri
Public Sub New (uriString As String)

Parameters

uriString
String

A string that identifies the resource to be represented by the Uri instance. Note that an IPv6 address in string form must be enclosed within brackets. For example, "http://[2607:f8b0:400d:c06::69]".

Exceptions

uriString is null.

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

uriString is empty.

-or-

The scheme specified in uriString is not correctly formed. See CheckSchemeName(String).

-or-

uriString contains too many slashes.

-or-

The password specified in uriString is not valid.

-or-

The host name specified in uriString is not valid.

-or-

The file name specified in uriString is not valid.

-or-

The user name specified in uriString is not valid.

-or-

The host or authority name specified in uriString cannot be terminated by backslashes.

-or-

The port number specified in uriString is not valid or cannot be parsed.

-or-

The length of uriString exceeds 65519 characters.

-or-

The length of the scheme specified in uriString exceeds 1023 characters.

-or-

There is an invalid character sequence in uriString.

-or-

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

Examples

The following example creates a Uri instance with the URI http://www.contoso.com/.

Uri^ baseUri = gcnew Uri( "http://www.contoso.com/" );
Uri myUri = new Uri("http://www.contoso.com/");
let myUri = Uri "http://www.contoso.com/"
Dim myUri As New Uri("http://www.contoso.com/")

Remarks

This constructor creates a Uri instance from a URI string. It parses the URI, puts it in canonical format, and makes any required escape encodings.

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

This constructor assumes that the string parameter references an absolute URI and is equivalent to calling the Uri constructor with UriKind set to Absolute. If the string parameter passed to the constructor is a relative URI, this constructor will throw a UriFormatException.

Applies to

Uri(SerializationInfo, StreamingContext)

Source:
Uri.cs
Source:
Uri.cs
Source:
Uri.cs

Caution

This API supports obsolete formatter-based serialization. It should not be called or extended by application code.

Initializes a new instance of the Uri class from the specified instances of the SerializationInfo and StreamingContext classes.

protected:
 Uri(System::Runtime::Serialization::SerializationInfo ^ serializationInfo, System::Runtime::Serialization::StreamingContext streamingContext);
protected Uri (System.Runtime.Serialization.SerializationInfo serializationInfo, System.Runtime.Serialization.StreamingContext streamingContext);
[System.Obsolete("This API supports obsolete formatter-based serialization. It should not be called or extended by application code.", DiagnosticId="SYSLIB0051", UrlFormat="https://aka.ms/dotnet-warnings/{0}")]
protected Uri (System.Runtime.Serialization.SerializationInfo serializationInfo, System.Runtime.Serialization.StreamingContext streamingContext);
new Uri : System.Runtime.Serialization.SerializationInfo * System.Runtime.Serialization.StreamingContext -> Uri
[<System.Obsolete("This API supports obsolete formatter-based serialization. It should not be called or extended by application code.", DiagnosticId="SYSLIB0051", UrlFormat="https://aka.ms/dotnet-warnings/{0}")>]
new Uri : System.Runtime.Serialization.SerializationInfo * System.Runtime.Serialization.StreamingContext -> Uri
Protected Sub New (serializationInfo As SerializationInfo, streamingContext As StreamingContext)

Parameters

serializationInfo
SerializationInfo

An instance of the SerializationInfo class containing the information required to serialize the new Uri instance.

streamingContext
StreamingContext

An instance of the StreamingContext class containing the source of the serialized stream associated with the new Uri instance.

Attributes

Exceptions

The serializationInfo parameter contains a null URI.

The serializationInfo parameter contains a URI that is empty.

-or-

The scheme specified is not correctly formed. See CheckSchemeName(String).

-or-

The URI contains too many slashes.

-or-

The password specified in the URI is not valid.

-or-

The host name specified in URI is not valid.

-or-

The file name specified in the URI is not valid.

-or-

The user name specified in the URI is not valid.

-or-

The host or authority name specified in the URI cannot be terminated by backslashes.

-or-

The port number specified in the URI is not valid or cannot be parsed.

-or-

The length of URI exceeds 65519 characters.

-or-

The length of the scheme specified in the URI exceeds 1023 characters.

-or-

There is an invalid character sequence in the URI.

-or-

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

Remarks

This constructor implements the ISerializable interface for the Uri class.

See also

Applies to

Uri(String, Boolean)

Source:
Uri.cs
Source:
Uri.cs
Source:
Uri.cs

Caution

The constructor has been deprecated. Please use new Uri(string). The dontEscape parameter is deprecated and is always false. https://go.microsoft.com/fwlink/?linkid=14202

Caution

This constructor has been deprecated; the dontEscape parameter is always false. Use Uri(string) instead.

Caution

The constructor has been deprecated. Please use new Uri(string). The dontEscape parameter is deprecated and is always false. http://go.microsoft.com/fwlink/?linkid=14202

Initializes a new instance of the Uri class with the specified URI, with explicit control of character escaping.

public:
 Uri(System::String ^ uriString, bool dontEscape);
[System.Obsolete("The constructor has been deprecated. Please use new Uri(string). The dontEscape parameter is deprecated and is always false. https://go.microsoft.com/fwlink/?linkid=14202")]
public Uri (string uriString, bool dontEscape);
[System.Obsolete("This constructor has been deprecated; the dontEscape parameter is always false. Use Uri(string) instead.")]
public Uri (string uriString, bool dontEscape);
[System.Obsolete("The constructor has been deprecated. Please use new Uri(string). The dontEscape parameter is deprecated and is always false. http://go.microsoft.com/fwlink/?linkid=14202")]
public Uri (string uriString, bool dontEscape);
public Uri (string uriString, bool dontEscape);
[<System.Obsolete("The constructor has been deprecated. Please use new Uri(string). The dontEscape parameter is deprecated and is always false. https://go.microsoft.com/fwlink/?linkid=14202")>]
new Uri : string * bool -> Uri
[<System.Obsolete("This constructor has been deprecated; the dontEscape parameter is always false. Use Uri(string) instead.")>]
new Uri : string * bool -> Uri
[<System.Obsolete("The constructor has been deprecated. Please use new Uri(string). The dontEscape parameter is deprecated and is always false. http://go.microsoft.com/fwlink/?linkid=14202")>]
new Uri : string * bool -> Uri
new Uri : string * bool -> Uri
Public Sub New (uriString As String, dontEscape As Boolean)

Parameters

uriString
String

A string that identifies the resource to be represented by the Uri instance. Note that an IPv6 address in string form must be enclosed within brackets. For example, "http://[2607:f8b0:400d:c06::69]".

dontEscape
Boolean

true if uriString is completely escaped; otherwise, false.

Attributes

Exceptions

uriString is null.

uriString is empty or contains only spaces.

-or-

The scheme specified in uriString is not valid.

-or-

uriString contains too many slashes.

-or-

The password specified in uriString is not valid.

-or-

The host name specified in uriString is not valid.

-or-

The file name specified in uriString is not valid.

-or-

The user name specified in uriString is not valid.

-or-

The host or authority name specified in uriString cannot be terminated by backslashes.

-or-

The port number specified in uriString is not valid or cannot be parsed.

-or-

The length of uriString exceeds 65519 characters.

-or-

The length of the scheme specified in uriString exceeds 1023 characters.

-or-

There is an invalid character sequence in uriString.

-or-

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

Examples

The following example creates a Uri instance for the URI http://www.contoso.com/Hello%20World.htm. Because the contained URI is completely escaped and is in canonical form, the dontEscape parameter can be set to true.

Uri^ myUri = gcnew Uri(  "http://www.contoso.com/Hello%20World.htm",true );
Uri myUri = new Uri("http://www.contoso.com/Hello%20World.htm", true);
let myUri = Uri("http://www.contoso.com/Hello%20World.htm", true)
Dim myUri As New Uri("http://www.contoso.com/Hello%20World.htm", True)

Remarks

This constructor creates a Uri instance from a URI string. It parses the URI and puts it in canonical format.

The dontEscape parameter controls whether reserved characters are translated into escape sequences. This parameter should be set to true only if you are certain that all reserved characters in the URI have been escaped. Setting the value to true for a URI that has not been completely escaped can cause unexpected behavior. It is strongly recommended that you always set this parameter to false.

If dontEscape is set to false, the constructor escapes any reserved characters by checking that all occurrences of percent (%) are followed by a valid escape sequence. If the character sequence following a percent is not valid, the percent is replaced by %25.

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

Applies to

Uri(String, UriCreationOptions)

Source:
Uri.cs
Source:
Uri.cs
Source:
Uri.cs

Initializes a new instance of the Uri class with the specified URI and additional UriCreationOptions.

public:
 Uri(System::String ^ uriString, UriCreationOptions % creationOptions);
public Uri (string uriString, in UriCreationOptions creationOptions);
new Uri : string * UriCreationOptions -> Uri
Public Sub New (uriString As String, ByRef creationOptions As UriCreationOptions)

Parameters

uriString
String

A string that identifies the resource to be represented by the Uri instance.

creationOptions
UriCreationOptions

Options that control how the Uri is created and behaves.

Applies to

Uri(String, UriKind)

Source:
Uri.cs
Source:
Uri.cs
Source:
Uri.cs

Initializes a new instance of the Uri class with the specified URI. This constructor allows you to specify if the URI string is a relative URI, absolute URI, or is indeterminate.

public:
 Uri(System::String ^ uriString, UriKind uriKind);
public Uri (string uriString, UriKind uriKind);
new Uri : string * UriKind -> Uri
Public Sub New (uriString As String, uriKind As UriKind)

Parameters

uriString
String

A string that identifies the resource to be represented by the Uri instance. Note that an IPv6 address in string form must be enclosed within brackets. For example, "http://[2607:f8b0:400d:c06::69]".

uriKind
UriKind

Specifies whether the URI string is a relative URI, absolute URI, or is indeterminate.

Exceptions

uriKind is invalid.

uriString is null.

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

uriString contains a relative URI and uriKind is Absolute.

or

uriString contains an absolute URI and uriKind is Relative.

or

uriString is empty.

-or-

The scheme specified in uriString is not correctly formed. See CheckSchemeName(String).

-or-

uriString contains too many slashes.

-or-

The password specified in uriString is not valid.

-or-

The host name specified in uriString is not valid.

-or-

The file name specified in uriString is not valid.

-or-

The user name specified in uriString is not valid.

-or-

The host or authority name specified in uriString cannot be terminated by backslashes.

-or-

The port number specified in uriString is not valid or cannot be parsed.

-or-

The length of uriString exceeds 65519 characters.

-or-

The length of the scheme specified in uriString exceeds 1023 characters.

-or-

There is an invalid character sequence in uriString.

-or-

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

Remarks

Relative and absolute URIs have different restrictions on their format. For example, a relative URI does not require a scheme or an authority. The value you specify in uriKind must match the type of URI passed in uriString. However, if RelativeOrAbsolute is specified, the URI string can be relative or absolute.

Applies to

Uri(Uri, String)

Source:
Uri.cs
Source:
Uri.cs
Source:
Uri.cs

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

public:
 Uri(Uri ^ baseUri, System::String ^ relativeUri);
public Uri (Uri baseUri, string relativeUri);
public Uri (Uri baseUri, string? relativeUri);
new Uri : Uri * string -> Uri
Public Sub New (baseUri As Uri, relativeUri As String)

Parameters

baseUri
Uri

The base URI.

relativeUri
String

The relative URI to add to the base URI.

Exceptions

baseUri is null.

baseUri is not an absolute Uri instance.

Note: 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 baseUri must start with c:\\.

Examples

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

Uri^ baseUri = gcnew Uri(  "http://www.contoso.com" );
Uri^ myUri = gcnew 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());
let baseUri = Uri "http://www.contoso.com"
let myUri = Uri(baseUri, "catalog/shownew.htm")

printfn $"{myUri}"
Dim baseUri As New Uri("http://www.contoso.com")
Dim myUri As New Uri(baseUri, "catalog/shownew.htm")

Console.WriteLine(myUri.ToString())

Remarks

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.

If the baseUri has relative parts (like /api), then the relative part must be terminated with a slash, (like /api/), if the relative part of baseUri is to be preserved in the constructed Uri.

Additionally, if the relativeUri begins with a slash, then it will replace any relative part of the baseUri

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

Applies to

Uri(Uri, Uri)

Source:
Uri.cs
Source:
Uri.cs
Source:
Uri.cs

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

public:
 Uri(Uri ^ baseUri, Uri ^ relativeUri);
public Uri (Uri baseUri, Uri relativeUri);
new Uri : Uri * Uri -> Uri
Public Sub New (baseUri As Uri, relativeUri As Uri)

Parameters

baseUri
Uri

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

relativeUri
Uri

A relative Uri instance that is combined with baseUri.

Exceptions

baseUri is not an absolute Uri instance.

baseUri is null.

baseUri is not an absolute Uri instance.

Note: 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 baseUri must start with c:\\.

Examples

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.
String^ addressString1 = "http://www.contoso.com/";
String^ addressString2 = "catalog/shownew.htm?date=today";
Uri^ absoluteUri = gcnew Uri(addressString1);

// Create a relative Uri from a string.  allowRelative = true to allow for 
// creating a relative Uri.
Uri^ relativeUri = gcnew Uri(addressString2);

// Check whether the new Uri is absolute or relative.
if (  !relativeUri->IsAbsoluteUri )
   Console::WriteLine( "{0} is a relative Uri.", relativeUri );

// Create a new Uri from an absolute Uri and a relative Uri.
Uri^ combinedUri = gcnew Uri( absoluteUri,relativeUri );
Console::WriteLine( combinedUri->AbsoluteUri );
// Create an absolute Uri from a string.
Uri absoluteUri = new Uri("http://www.contoso.com/");

// Create a relative Uri from a string.  allowRelative = true to allow for
// creating a relative Uri.
Uri relativeUri = new Uri("/catalog/shownew.htm?date=today", UriKind.Relative);

// Check whether the new Uri is absolute or relative.
if (!relativeUri.IsAbsoluteUri)
    Console.WriteLine("{0} is a relative Uri.", relativeUri);

// Create a new Uri from an absolute Uri and a relative Uri.
Uri combinedUri = new Uri(absoluteUri, relativeUri);
Console.WriteLine(combinedUri.AbsoluteUri);
// Create an absolute Uri from a string.
let absoluteUri = Uri "http://www.contoso.com/"

// Create a relative Uri from a string.  allowRelative = true to allow for
// creating a relative Uri.
let relativeUri = Uri("/catalog/shownew.htm?date=today", UriKind.Relative)

// Check whether the new Uri is absolute or relative.
if not relativeUri.IsAbsoluteUri then
    printfn $"{relativeUri} is a relative Uri."

// Create a new Uri from an absolute Uri and a relative Uri.
let combinedUri = Uri(absoluteUri, relativeUri)
printfn $"{combinedUri.AbsoluteUri}"
    ' 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

Remarks

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.

If the baseUri has relative parts (like /api), then the relative part must be terminated with a slash, (like /api/), if the relative part of baseUri is to be preserved in the constructed Uri.

Additionally, if the relativeUri begins with a slash, then it will replace any relative part of the baseUri

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

Applies to

Uri(Uri, String, Boolean)

Source:
Uri.cs
Source:
Uri.cs
Source:
Uri.cs

Caution

The constructor has been deprecated. Please new Uri(Uri, string). The dontEscape parameter is deprecated and is always false. https://go.microsoft.com/fwlink/?linkid=14202

Caution

This constructor has been deprecated; the dontEscape parameter is always false. Use Uri(Uri, string) instead.

Caution

The constructor has been deprecated. Please new Uri(Uri, string). The dontEscape parameter is deprecated and is always false. http://go.microsoft.com/fwlink/?linkid=14202

Initializes a new instance of the Uri class based on the specified base and relative URIs, with explicit control of character escaping.

public:
 Uri(Uri ^ baseUri, System::String ^ relativeUri, bool dontEscape);
[System.Obsolete("The constructor has been deprecated. Please new Uri(Uri, string). The dontEscape parameter is deprecated and is always false. https://go.microsoft.com/fwlink/?linkid=14202")]
public Uri (Uri baseUri, string? relativeUri, bool dontEscape);
[System.Obsolete("This constructor has been deprecated; the dontEscape parameter is always false. Use Uri(Uri, string) instead.")]
public Uri (Uri baseUri, string? relativeUri, bool dontEscape);
[System.Obsolete("The constructor has been deprecated. Please new Uri(Uri, string). The dontEscape parameter is deprecated and is always false. http://go.microsoft.com/fwlink/?linkid=14202")]
public Uri (Uri baseUri, string relativeUri, bool dontEscape);
public Uri (Uri baseUri, string relativeUri, bool dontEscape);
[System.Obsolete("The constructor has been deprecated. Please new Uri(Uri, string). The dontEscape parameter is deprecated and is always false. https://go.microsoft.com/fwlink/?linkid=14202")]
public Uri (Uri baseUri, string relativeUri, bool dontEscape);
[<System.Obsolete("The constructor has been deprecated. Please new Uri(Uri, string). The dontEscape parameter is deprecated and is always false. https://go.microsoft.com/fwlink/?linkid=14202")>]
new Uri : Uri * string * bool -> Uri
[<System.Obsolete("This constructor has been deprecated; the dontEscape parameter is always false. Use Uri(Uri, string) instead.")>]
new Uri : Uri * string * bool -> Uri
[<System.Obsolete("The constructor has been deprecated. Please new Uri(Uri, string). The dontEscape parameter is deprecated and is always false. http://go.microsoft.com/fwlink/?linkid=14202")>]
new Uri : Uri * string * bool -> Uri
new Uri : Uri * string * bool -> Uri
Public Sub New (baseUri As Uri, relativeUri As String, dontEscape As Boolean)

Parameters

baseUri
Uri

The base URI.

relativeUri
String

The relative URI to add to the base URI.

dontEscape
Boolean

true if baseUri and relativeUri are completely escaped; otherwise, false.

Attributes

Exceptions

baseUri is null.

baseUri is not an absolute Uri instance.

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 baseUri must start with c:\\.

Examples

The following example creates a new instance of the Uri class by combining the relative URIs http://www.contoso.com and Hello%20World.htm to form an absolute URI.

Uri^ baseUri = gcnew Uri( "http://www.contoso.com/" );
Uri^ myUri = gcnew Uri( baseUri,"Hello%20World.htm",false );
Uri baseUri = new Uri("http://www.contoso.com");
Uri myUri = new Uri(baseUri, "Hello%20World.htm",false);
let baseUri = Uri "http://www.contoso.com"
let myUri = Uri(baseUri, "Hello%20World.htm", false)
Dim baseUri As New Uri("http://www.contoso.com")
Dim myUri As New Uri(baseUri, "Hello%20World.htm", False)

Remarks

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

The dontEscape parameter controls whether reserved characters are translated into escape sequences. This parameter should be set to true only if you are certain that all reserved characters in the URI have been escaped. Setting the value to true for a URI that has not been completely escaped can cause unexpected behavior. It is strongly recommended that you always set this parameter to false. If dontEscape is set to false, the constructor escapes any reserved characters by checking that all occurrences of percent (%) are followed by a valid escape sequence. If the character sequence following a percent is not valid, the percent is replaced by %25.

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

Notes to Callers

Because of security concerns, your application should not call this constructor with URI strings from untrusted sources and with dontEscape set to true. Alternately, you can check a URI string for validity by calling the IsWellFormedOriginalString() method prior to calling this constructor.

Applies to