5

I have a reference to an item that uses the sitecore: protocol:

"sitecore://master/{...GUID HERE...}?lang=en&ver=0"

I could attempt to parse this URI manually to look up the item, but I'm pretty certain there's an existing utility somewhere to do this.

Of course, searching for sitecore: protocol URIs leads to a lot of answers about generating URLs from items, and that's not what I want in this case.

2 Answers 2

9

It's Sitecore.Data.ItemUri format. You can use

var itemUri = ItemUri.Parse(string itemUriString)

to get ItemUri class object and then

Sitecore.Data.Database.GetItem(ItemUri itemUri)

to get the Item

5

This is a Sitecore ItemUri.

In general, references in Sitecore take one of these forms:

  • .ID: {DAC24EDD-44FB-42EF-9ECD-1E8DAF706386}
  • .Uri: sitecore://master/{DAC24EDD-44FB-42EF-9ECD-1E8DAF706386}?lang=en&ver=1
  • .DataUri: sitecore://{DAC24EDD-44FB-42EF-9ECD-1E8DAF706386}?lang=en&ver=1
  • .ItemUri: sitecore://master/{DAC24EDD-44FB-42EF-9ECD-1E8DAF706386}?lang=en&ver=1
  • .VersionUri: en, 1

It can be constructed from a String, like this:

var uri = ItemUri.Parse(yourString);
var uri = DataUri.Parse(yourString);

(examples)

For further reference, I blogged about this a while back. Know your item, remember your context.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.