Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Aung Zin Phyo 17 posts 87 karma points
    Jan 09, 2020 @ 08:10
    Aung Zin Phyo
    0

    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.

            string test = umb://document/53d62b4d52d2414fb0882d263cfd6e85;
            var udi = Udi.Parse(test);
            var page = Services.ContentService.GetById(udi);**
    

    this code is error.please help me.

  • Bo Jacobsen 562 posts 2268 karma points
    Jan 09, 2020 @ 08:25
    Bo Jacobsen
    1

    Hi Aung.

    You can do 2 things.

    var udiAsString = "umb://document/53d62b4d52d2414fb0882d263cfd6e85";
    var udiSubString = udiAsString.Substring(udiAsString.Length - 32);
    var guid = Guid.ParseExact(udiSubString, "N");
    var page = Services.ContentService.GetById(guid);
    

    or

    string test = "umb://document/53d62b4d52d2414fb0882d263cfd6e85";
    var udi = Udi.Parse(test);
    var cachedPage = Umbraco.Content(udi);
    var page = Services.ContentService.GetById(cachedPage.Id);
    
  • Patrick van Kemenade 97 posts 325 karma points
    Apr 27, 2021 @ 09:41
    Patrick van Kemenade
    0

    Beats me why there isn't a simple ontentService.GetByIUdi(..)

    Anyway, another solution is:

    var guidUdi = udiValue as GuidUdi;
    
    if(guidUdi  != null){ 
    var page = Services.ContentService.GetById(uidUdi.Guid);
    }
    
Please Sign in or register to post replies

Write your reply to:

Draft