Possibility to search for block from folder other than ContentReference.SiteBlockFolder

Member since: 2010

I want to search a block with specific property set to some value. This is my code:

 var contentRepo = ServiceLocator.Current.GetInstance<IContentRepository>();

            var allBlocks = contentRepo.GetDescendents(ContentReference.SiteBlockFolder);
            
            foreach (var block in allBlocks)
            {
                var content = contentRepo.Get<BlockData>(block);
                var subStepBlock = content as CertificationSubStepBlock;
                if (subStepBlock != null)
                {
                    if (subStepBlock.Code == code)
                    {
                        return subStepBlock;
                    }
                }
            }

I am caching this, but is there a way to improve performances by search from specific block folder ID on? How would I see the ID of the folder in edit mode?

#66022 Feb 18, 2013 16:47
  • Member since: 2004

    I guess you are not using EPiServer.Find in your project? Otherwise that would be the nicest solution.

    From your pseudocode it looks like you are interested of a certain block type? If that is the case then you might want to use IContentModelUsage.ListContentOfContentType that will give you references to alll instances of your block type.

    You would then still have to load and iterate over them to find which that matches your criteria, but with this approach you only load blocks of your wanted type and not all blocks as the case will be with GetDecendents.

     

    #66054 Feb 19, 2013 7:21