asahin
asahin

Reputation: 79

What is difference between UriKind.Relative and UriKind.Absolute?

What is difference between UriKind.Relative, UriKind.Absolute, and UriKind.RelativeOrAbsolute?

Upvotes: 6

Views: 11738

Answers (2)

Bhaskar Singh
Bhaskar Singh

Reputation: 430

UriKind.Relative: Relative Uri would be "relative to the project's structure, with a forward-slash character / we're specifying the root from the project. Example:

new Uri("/index.html ", UriKind.Relative)

UriKind.Absolute: Absolute URIs are Complete url, which start with protocol name Example:

new Uri("http://www.testdomain.com/index.html ", UriKind.Absolute)

UriKind.RelativeOrAbsolute: in this case runtime will figure it out for itself and It will attempt to clean up the UriString we provide and figure out where resources are.

Upvotes: 1

BobHy
BobHy

Reputation: 1734

Some APIs require absolute URIs, others relative URIs but most don't care. By creating the Uri with the corresponding UriKind argument, (e.g, new Uri(*yourString*, UriKind.Absolute), you ensure that the API will get the kind of Uri it can handle. But the price of this assurance is that you'll have to handle an exception from the Uri constructor. But at least you're handling the potential error closer to the source of the problem and should be able to provide a better user experience thereby.

Upvotes: 1

Related Questions