Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.
This topic has not yet been rated - Rate this topic

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

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
)

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

Silverlight-based applications are cross-platform, so they run in most modern Web browsers, including Apple Safari version 2.0 and later on Apple Mac OS X. However, TryCreate(String, UriKind, Uri) does not convert backslashes in the uriString parameter to forward slashes in the Uri on Apple Mac OS X.

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";
}


Silverlight

Supported in: 5, 4, 3

Silverlight for Windows Phone

Supported in: Windows Phone OS 7.1, Windows Phone OS 7.0

XNA Framework

Supported in: Xbox 360, Windows Phone OS 7.0

For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.

Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

Show:
© 2014 Microsoft. All rights reserved.