Click to Rate and Give Feedback
MSDN
MSDN Library
.NET Development
.NET Framework 3.5
System Namespace
Uri Class
Uri Constructor
 Uri Constructor (String)

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

Other versions are also available for the following:
.NET Framework Class Library
Uri Constructor (String)

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

Namespace:  System
Assembly:  System (in System.dll)
Visual Basic (Declaration)
Public Sub New ( _
    uriString As String _
)
Visual Basic (Usage)
Dim uriString As String

Dim instance As New Uri(uriString)
C#
public Uri(
    string uriString
)
Visual C++
public:
Uri(
    String^ uriString
)
JScript
public function Uri(
    uriString : String
)

Parameters

uriString
Type: System..::.String
A URI.
ExceptionCondition
ArgumentNullException

uriString is nullNothingnullptra null reference (Nothing in Visual Basic).

UriFormatException

uriString is empty.

-or-

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

-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 65534 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:\\.

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.

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

Visual Basic
Dim myUri As New Uri("http://www.contoso.com/")


C#
Uri myUri = new Uri("http://www.contoso.com/");


Visual C++
Uri^ baseUri = gcnew Uri( "http://www.contoso.com/" );

JScript
    var myUri : Uri = new Uri("http://www.contoso.com/");

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