Using Windows Explorer, the end user can delete Shell Items.
It can be done using context menus (if the ‘Delete’ menu item is visible), or
by pressing the DEL key while the item is selected. In all cases, the item can
only be renamed if the corresponding ShellItem instance has its CanDelete
property set to true. By default, it’s not.
Deleting is done item by item. A folder can perfectly
contain items (including sub folders) that can be deleted and others that
If a ShellItem supports deleting, to handle the
delete operation of a ShellItem instance, you must override the OnOperate()
method of the parent folder class:
protected virtual void OnOperate(ShellOperationEventArgs e)
The event argument contains the type of operation and its
context (the item being deleted, etc.). So for example, here is an
implementation of OnOperate:
protected override void OnOperate(ShellOperationEventArgs e)
private void OnRemove(ShellOperationEventArgs e)
// TODO: remove a folder
// TODO: remove an item
Note: if the ShellItem instance represents a physical
file item, the default implementation of OnOperate() will delete the
physical file, so the method does not need to be overridden in that case.
Depending on how the end user deletes an item, the operation
can be RecycleItem instead of RemoveItem. Again, if the ShellItem
instance represents a physical file item, the RecycleItem operation
implementation will put the physical file in the recycle bin, so the method
does not need to be overridden in that case.
Once the item in the recycle bin, the end-user will be able
to restore it to its original folder.