Luke Warren Dev
Software Development Tips and Stories When I feel Like It

How to get all Content by Document Type in Umbraco

This is probably going to be my shortest post yet. After having messed around with Umbraco for the last few weeks I thought that I would share some code!

Categories: C# , Umbraco
Tags: Umbraco , C# , Document Types

OK, straight to it

Please note that on large sites you probably want to cache the results of the method to avoid a performance hit.

public static IEnumerable<IPublishedContent> GetAllNodesByType(IPublishedContent home, string docTypeAlias)
        var foundNodes = new List<IPublishedContent>();
        foreach (var content in home.Children)
            if (content.DocumentTypeAlias == docTypeAlias)

            // Check recursive
            if (content.Children.Count() > 0)
                foundNodes.AddRange(GetAllNodesByType(content, docTypeAlias));
        return foundNodes;

comments powered by Disqus