Try our conversational search powered by Generative AI!

Delete Orphan Blocks

Episerver 8 CMS. 
I want to code a scheduled job to delete all the orphan blocks. I created them programatically, all are of the same typeblock. I'm not sure how to select and delete this blocks programatically from a scheduled job.
Nov 10, 2015 17:26


You could try to use this code snippet:

  var contentType = ServiceLocator.Current.GetInstance<IContentTypeRepository>().List().FirstOrDefault(ct=>ct.ModelType == typeof(JumbotronBlock));
            var contentList = ServiceLocator.Current.GetInstance<ContentStore>().ListContentOfContentType(contentType, false).ToList();
            var contentRepository = ServiceLocator.Current.GetInstance<IContentRepository>();
            var contentCount = contentList.Count;
            for (int i = 0; i < contentCount; i++)
                var contentUsage = contentList[i];
                contentRepository.Delete(contentUsage.ContentLink, false, AccessLevel.NoAccess);
Nov 10, 2015 20:56

Thank you Grzegorz Wiecheć , it worked!!!!!


Nov 11, 2015 9:45
This topic was created over six months ago and has been resolved. If you have a similar question, please create a new topic and refer to this one.
* 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.