Copied to clipboard

Flag this post as spam?

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


  • ivan 36 posts 177 karma points
    May 24, 2021 @ 16:40
    ivan
    0

    Get Update date and edited by by culture.

    Hello Everyone, Good Day. I got all the content by culture but I can't get the update date by culture. There is no difference between the two. Is there any way to get the update date and updated by for every culture? Below is my code of getting all the content by culture.

            var getAllContent = new List<GetAllContentByCulture>();
    
            foreach (var clture in Umbraco.ContentAtRoot().First().Cultures)
            {
                var getContentProperties = new List<ContentProperty>();
    
                // This is how the culture is set for the context we are in
                _variationContextAccessor.VariationContext = new VariationContext(clture.Key);
    
                var allPublishedContent = new List<IPublishedContent>();
    
                foreach (var publishedContentRoot in Umbraco.ContentAtRoot())
                {
                    allPublishedContent.AddRange(publishedContentRoot.DescendantsOrSelf());
                }
    
                foreach (var c in allPublishedContent)
                {
    
                    if (c.Name == "Settings" || c.Name == "General" || c.Name == "Theme")
                    {
                        continue;
                    }
    
                    getContentProperties.Add(new ContentProperty
                    {                       
                        id = c.Id,
                        pagename = c.Name,
                        lasteditdate = c.UpdateDate.ToString("MMM-dd-yyyy h:mm tt"),
                        editedby = c.WriterName.ToString(),
                        url = c.Url.ToString()
                    });
                }
    
                getAllContent.Add(new GetAllContentByCulture
                {
                    language = clture.Key,
                    contentProperties = getContentProperties
                });
    
    
            }
    
  • Joep 96 posts 698 karma points
    May 26, 2021 @ 15:34
    Joep
    0

    Hi,

    You can get this data by using the ContentService.

    var node = ContentService.GetById({nodeid});
    var publishDate= node.GetUpdateDate({culture code});
    

    This gets the latest date when the item was updated. You can also use GetPublishDate to get the latest date the culture was published.

    -Joep

  • Joep 96 posts 698 karma points
    May 26, 2021 @ 15:38
    Joep
    100

    Ah when writing the previous answer, I found an other extension. In your code you can use c.CultureDate(clture.Key) to get the latest published date.

  • ivan 36 posts 177 karma points
    Jun 30, 2021 @ 09:12
    ivan
    100

    Hello Joep,

    Thanks! I got it correct by doing this c.Cultures[clture.Key].Date.

    Regards, Ivan

Please Sign in or register to post replies

Write your reply to:

Draft