syed Ahsan Jaffri
syed Ahsan Jaffri

Reputation: 1124

Get Collection of items by pipe separated GUIDs in sitecore

Basically I used multi-list in rendering parameter for an category selection. so i got pipe separated GUIDs of selected item & needs to get a collection of items, is there any method supported by Sitecore api instead of iterating in loop. that could be expensive in terms of efficiency as compare to any built-in Sitecore method.

Upvotes: 3

Views: 2951

Answers (2)

Matthew Dresser
Matthew Dresser

Reputation: 11442

Another way, avoiding a potential ArgumentNullException (in the case of item.Fields["field name"] being null) is to use Sitecore.Data.ID.ParseArray in combination with a linq statement to get a list of items as follows:

var items = ID.ParseArray(item["field name"])
               .Select(id => item.Database.GetItem(id)).ToList();

Upvotes: 6

Martin Davies
Martin Davies

Reputation: 4456

There is a MultilistField class in Sitecore.Data.Fields, used as follows

var mlf = new MultilistField(item.Fields["field name"]).
mlf.GetItems();

I don't think it's any more efficient than what you're already doing though. In fact, it probably does just the same internally.

Upvotes: 8

Related Questions