Search code examples
c#n2cms

Programmatically Removing N2 CMS Nodes from the Trash


Within N2 CMS, is there a way to programmatically remove nodes from the trash?


Solution

  • I figured it out. In this example models of type TargetDetailModel are being permanently deleted from the N2 CMS trash.

    var trash = new ItemList<TrashContainerItem>(N2.Find.RootItem.Children, new TypeFilter(typeof(TrashContainerItem))).FirstOrDefault();
    if (trash != null)
    {
      var detailToPermDelete = new ItemList<TargetDetailModel>(trash.Children, new TypeFilter(typeof(TargetDetailModel)));
      for (int permDeleteCount = 0; permDeleteCount < detailToPermDelete.Count; permDeleteCount++)
      {                            
        N2.Context.Current.Persister.Delete(detailToPermDelete.ElementAt(permDeleteCount));
      }
    }