Vulnerability in EPiServer.Forms

Try our conversational search powered by Generative AI!

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


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?

Feb 18, 2013 16:47

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.


Feb 19, 2013 7:21
This thread is locked and should be used for reference only. Please use the Episerver CMS 7 and earlier versions forum to open new discussions.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.