I have the following block of code that retrieves a documen开发者_C百科t 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);
}
}
}
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);
精彩评论