Copied to clipboard

Flag this post as spam?

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


  • Simon 81 posts 184 karma points
    Jun 05, 2017 @ 17:31
    Simon
    0

    How to get an item's UDI without hitting the database?

    Hi,

    Trying to find how to get an items unique identifier - used to be an integer but now an Umbraco formatted string e.g. umb://document/4fed18d8c5e34d5e88cfff3a5b457bf2

    I have an Author/Content set up and store the Author as a ContentPicker2 - which stores the item as the new UDI. However, I now have an Examine index set up to look at my Author property.

    On the Author Profile page, I use this Examine Index to find the content attributed to that Author. How can I find the UDI of the Author's page to then pass to Examine?

    Please let me know if what you propose requires a trip to the database as I'd prefer to avoid as many of those as possible!

    Thanks Simon

  • Alex Skrypnyk 6182 posts 24284 karma points MVP 8x admin c-trib
    Jun 10, 2017 @ 00:28
    Alex Skrypnyk
    1

    Hi Simon

    Past days this code helped me a lot to get udi of iPublishedContent:

     var modelWithKey = Model.Content.Unwrap() as IPublishedContentWithKey;
     var key = modelWithKey.GetKey();
    
  • Simon 81 posts 184 karma points
    Jun 17, 2017 @ 18:23
    Simon
    0

    Thanks Alex - great solution!

  • Andy Robinson 9 posts 96 karma points c-trib
    Jun 26, 2017 @ 13:28
    Andy Robinson
    3

    I needed to do this on an APIController perceptive, discovered this today that seems to format the UDI properly, including getting rid of those pesky dashes from the guid

    IPublishedContent page =  _helper.UmbracoContext.ContentCache.GetById(1156);
    
    var udi = new GuidUdi("document", Model.Content.GetKey());
    

    Ref: https://our.umbraco.org/apidocs/csharp/api/Umbraco.Core.GuidUdi.html

  • David Armitage 510 posts 2082 karma points
    Sep 02, 2021 @ 10:53
    David Armitage
    1

    Hi,

    Here is how I do it

     Udi.Create(Constants.UdiEntityType.Document, "the guild key here")
    
  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies