TryCreate Method (String, UriKind, Uri)
Collapse the table of content
Expand the table of content

Uri.TryCreate Method (String, UriKind, Uri%)

[ This article is for Windows Phone 8 developers. If you’re developing for Windows 10, see the latest documentation. ]

Creates a new Uri using the specified String instance and a UriKind.

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

Public Shared Function TryCreate ( _
	uriString As String, _
	uriKind As UriKind, _
	<OutAttribute> ByRef result As Uri _
) As Boolean


Type: System.String
The String representing the Uri.
Type: System.UriKind
The type of the Uri.
Type: System.Uri %
When this method returns, contains the constructed Uri.

Return Value

Type: System.Boolean
A Boolean value that is true if the Uri was successfully created; otherwise, false.

If this method returns true, the new Uri is in result.

Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows CE Platform Note: The .NET Compact Framework does not differentiate between relative and absolute paths. The uriKind parameter is not evaluated.

' String to create.
Dim addressString As String = "catalog/shownew.htm?date=today"
' Parse the string and create a new Uri instance, if possible.
Dim result As Uri = Nothing
If Uri.TryCreate(addressString, UriKind.RelativeOrAbsolute, result) Then
  ' The call was successful. Write the URI address to the console.
  outputBlock.Text &= result.ToString()

  ' Check whether new Uri instance is absolute or relative.
  If result.IsAbsoluteUri Then 
     outputBlock.Text &= " is an absolute Uri."
     outputBlock.Text &= vbCrLf
     outputBlock.Text += " is a relative Uri"
     outputBlock.Text &= vbCrLf
  End If    
  ' Let the user know that the call failed.
  outputBlock.Text &= "addressString could not be parsed as a URI "
  outputBlock.Text &= "address."
  outputBlock.Text &= vbCrLf
End If

Windows Phone OS

Supported in: 8.1, 8.0, 7.1, 7.0

Windows Phone

© 2017 Microsoft