Reputation: 1124
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
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
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