Item Delete

Using Explorer, an end user can delete Shell items. This 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 be renamed only if the corresponding ShellItem instance has its CanDelete property set to true. By default, the property is false.

Deleting is accomplished item by item. A folder may contain items (including subfolders) that can be deleted and others that cannot.

If a ShellItem supports the deletion operation, you must override the OnOperate() method of the parent folder class to implement deletion:

protected virtual void OnOperate(ShellOperationEventArgs e)

The event argument contains the type of operation and its context (e.g., the item being deleted). Following is a sample implementation of OnOperate:

protected override void OnOperate(ShellOperationEventArgs e)
{
    switch (e.Operation)
    {
        case ShellOperation.RemoveItem:
            OnRemove(e);
            break;
    }
}
 
private void OnRemove(ShellOperationEventArgs e)
{
    if (e.Item.IsFolder)
    {
        // TODO: remove a folder
        return;
    }
 
    // TODO: remove an item
}

Note: If the ShellItem instance represents a physical file item, the default implementation of OnOperate() will delete the physical file. In that case, the method does not need to be overridden.

Recycle Bin Support

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. In that case, the method does not need to be overridden.

Once the item is in the recycle bin, the end user will be able to restore it to its original folder.

Copyright (c) 2022 Callback Technologies, Inc. - All rights reserved.
CBFS Shell 2022 .NET Edition - Version 22.0 [Build 8172]