Using the contentpicker2 with the UDI. Need to grab the selected content item in an eventhandler with ContentService or IContent.GetValue<> but there doesnt seam to any propertyvalueconverters or methods that can use the UDI that is stored.
ideally for front end stuff you should use the Umbraco.TypedContent helpers as this gets stuff from the cache. where you can pass the UDI directly
var item = Umbraco.TypedContent(myUdi);
however - if you do need the backoffice content:
you can get a number of uid's with
var items = Services.ContentService.GetByIds(new List<Udi> { myUdi } )
but that returns a list of multiple items; If you just want one, then there isn't a direct function - you can get the GUID from the UDI and call that.
var guidUdi = myUdi as GuidUdi;
if (guidUdi != null)
{
var item = Services.ContentService.GetById(guidUdi.Guid);
}
This turns the Udi into a GuidUdi and then lets you directly get the Guid - ideally you would also check this is infact a content Udi before you did this - but it hopefully shows you how you might do it.
UDI and ContentService / GetValue<>
Using the contentpicker2 with the UDI. Need to grab the selected content item in an eventhandler with ContentService or IContent.GetValue<> but there doesnt seam to any propertyvalueconverters or methods that can use the UDI that is stored.
Or?
Hi
ideally for front end stuff you should use the Umbraco.TypedContent helpers as this gets stuff from the cache. where you can pass the UDI directly
however - if you do need the backoffice content:
you can get a number of uid's with
but that returns a list of multiple items; If you just want one, then there isn't a direct function - you can get the GUID from the UDI and call that.
This turns the Udi into a GuidUdi and then lets you directly get the Guid - ideally you would also check this is infact a content Udi before you did this - but it hopefully shows you how you might do it.
is working on a reply...