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 static bool TryCreate(
	string uriString,
	UriKind uriKind,
	out Uri result


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.
string addressString = "catalog/shownew.htm?date=today";
// Parse the string and create a new Uri instance, if possible.
Uri result = null;
if (Uri.TryCreate(addressString, UriKind.RelativeOrAbsolute, out result) == true) {
   // 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) {
      outputBlock.Text += " is an absolute Uri.\n";
   else {
      outputBlock.Text += " is a relative Uri.\n";
else {
   // Let the user know that the call failed.
   outputBlock.Text += "addressString could not be parsed as a URI ";
   outputBlock.Text += "address.\n";

Windows Phone OS

Supported in: 8.1, 8.0, 7.1, 7.0

Windows Phone

© 2017 Microsoft