Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Kentico TreeNode Delete method not deleting dependencies

I have the following block of code that retrieves a document node in kentico and deletes it. It does delete the kentico node, but not the underlying document type which stays in the datase. Help?!

CMS.TreeEngine.TreeProvider provider = new CMS.TreeEngine.TreeProvider(CMS.CMSHelper.CMSContext.CurrentUser);
CMS.TreeEngine.TreeNode image = provider.SelectSingleNode(new Guid(imageID), "en-US", CMS.CMSHelper.CMSContext.CurrentSite.SiteName);

if (image != null)
{
    CMS.TreeEngine.TreeNode school = provider.SelectSingleNode(image.Parent.NodeID, "en-US", true, true);
    if (school != null)
    {
        string CMSUserID = school.GetValue("CMSUserID").ToString();
        if (CMSUserID == ui.UserID.ToString())
        {
            image.Delete(false);                                        
        }
    }
}
like image 342
Grimboify Avatar asked Jul 19 '11 01:07

Grimboify


1 Answers

You need to use the DeleteDocument method from the CMS.WorkflowEngine namespace. It ensures that all dependent objects are deleted.

DocumentHelper.DeleteDocument(image, provider, true, true, true);

like image 103
Ben E G Avatar answered Oct 27 '22 01:10

Ben E G