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.
Assembly: System (in System.dll)
Parameters
- uriString
- Type: System.String
The String representing the Uri.
- uriKind
- Type: System.UriKind
The type of the Uri.
- result
- Type:
System.Uri
%
When this method returns, contains the constructed Uri.
Return Value
Type: System.BooleanA 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"; }
Show: