Document parentNode = new Document(1350);//use id of parent node
foreach (Document child in parentNode.Children)
{
child.delete();
umbraco.library.UpdateDocumentCache(child.Id);
}
umbraco.library.RefreshContent();
You'd need to hang that off a button somewhere, guess easiest would be make a user control and stick it in a doc restricted to admins, else you could make something in the umbraco admin if you're into that.
I used ContentService (https://our.umbraco.org/documentation/Reference/Management-v6/Services/ContentService).
See the snipet below (vb.net)
Private Sub MyDeleteSub(id as integer) Dim cs = umbraco.Core.ApplicationContext.Current.Services.ContentService Dim page = cs.GetById(id) cs.Delete(page) End Sub
Deleting Child Nodes
Hi,
Does anyone know of a way of deleting all child nodes from a node without going through each one individually.
The node in questions has 100+ items within it and is one of many.
I am guessing this issue isn't unique to me and someone may know of a package that can do this.
Thanks
John
PS
Sorry for my first post to be a cry for help.
Hmm, well, I'm going to develop a 'Bulk Actions' package for Umbraco next week or so, but that doesn't help you at this point ;-)
You can delete the parent node, that will delete all the child nodes.. But you'd have to recreate the parent. Still, it would save you some time.. ;-)
You can do it in code something like this:
Document parentNode = new Document(1350);//use id of parent node foreach (Document child in parentNode.Children) { child.delete(); umbraco.library.UpdateDocumentCache(child.Id); } umbraco.library.RefreshContent();
You'd need to hang that off a button somewhere, guess easiest would be make a user control and stick it in a doc restricted to admins, else you could make something in the umbraco admin if you're into that.
You need to ref umbraco cms.dll too
just a thought, how about adding the "delete all children" option (with a confirmation dialog) to the right click context menu on the content tree ?
http://umbraco.tv/documentation/videos/for-developers/events/add-items-to-the-context-menu
Hi Thanks for the reply's I created a user control to delete the node, when i find time i will create a package i think which adds this.
Thanks
John
I
I used ContentService (https://our.umbraco.org/documentation/Reference/Management-v6/Services/ContentService).
See the snipet below (vb.net)
(Sorry my English. I'm Brazilian)
Also might be worth to check our free version of bulkmanager that does this. http://soetemansoftware.nl/bulkmanager
Cheers,
Richard
Thanks,
I'll try it tomorrow.
Eduardo
is working on a reply...