Delete node from .NET usercontrol Options
BehnReady
Posted: Monday, November 20, 2006 8:39:14 PM
Rank: Newbie

Joined: 8/15/2006
Posts: 8
Is it possible to delete a node programmatically from a usercontrol?
I have a node object, but it doesn't appear to have a delete method.

Thanks in advance.
Martin Andersen
twynham
Posted: Tuesday, November 21, 2006 11:24:30 AM
Rank: Devotee

Joined: 7/28/2006
Posts: 57
There is a delete method for the Document object... something like this...

Code:

using umbraco.cms.businesslogic.web;

void deleteById(int nodeID)
{
  Document objDel = new Document(nodeID);
  objDel.delete();
}


Notes (things I've discovered):

1. This just seems to remove the references to the ID from the database (children, node, properties, versions, document types, etc).

2. If you don't then do a republish all, then the XML tree is different from the database. This can cause problems if you're subsequently using the XML tree to find nodes that now don't exist in the database. At the very least, your browsers won't see a change in the website until there is a republish all.

3. Keep a backup of the database in case you muck things up! What's good is that most things are quite easy to fix as the structure of the database is quite logical and well thought out.

4. DO USE THE APIs, DON'T SIMPLY TRY AND DELETE FROM THE DATABASE. You are asking for trouble, esp. as you'll probably leave loads of stuff in that can then break the GUI.

5. As an aside, I'm just trying to figure out why the nodes aren't being removed from the system index in my setup... The delete method should remove then, it's just there is an exception. The system index appears to be a lucene index under _systemindexdonotdelete - and is used in the clever AJAX "find" function on the GUI. Not so clever when it finds a node that has been removed from the database but not the index - resulting in a system null exception. Niels may be able to shed some light on all this... :)

Hope this helps.

S.

Bawden Quinn Associates, UK
BehnReady
Posted: Thursday, January 25, 2007 11:29:04 PM
Rank: Newbie

Joined: 8/15/2006
Posts: 8
Sorry for the long delay, but thank you for your great answer, it works perfectly.

Regards
Martin Andersen
Users browsing this topic
Guest


You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.