Trash - for Developers

From Sense/Net Wiki
Jump to: navigation, search
  • 100%
  • 6.0
  • Enterprise
  • Community
  • Planned


Trash bin

The Trash Bin is a built-in feature of the Sense/Net ECMS. Visit the main Trash Bin page to see all aspects of this feature. As a developer, you can write your own Portlet or module that puts deleted or spare contents to the trash or you can control the trash behavior of your custom content types.


Delete to trash means that the content will be wrapped into a special container called the Trash Bag and will be moved to a central place called the Trash Bin. The path of the trash in the repository is /Root/Trash.

Trash Bag

The Trash Bag is a simple container content that 'wraps' the deleted content. You can access the deleted item through the DeletedContent property of the Trash Bag.

var dc = trashBag.DeletedContent;
if (dc != null)
	contentLabel.Text = dc.DisplayName;


The content moved to the trash will preserve its actual permissions and the container Trash Bag will get all its inherited permissions. This means that if you delete a content that only few users can see, other users won't see it in the trash either.

Delete content

You can move contents to the trash, if:

  • trash is enabled in the system and
  • trash is enabled on the container of the particular content

If the trash is disabled globally or the trash functionality is disabled locally on the container, the content will be deleted permanently. See documentation for system operators how to enable/disable these features. If everything is set, the following code will move your content to the trash:

var book = Node.LoadNode(bookPath);

It is possible that something goes wrong during this operation, for example the actual user does not have the necessary permissions to put items into the trash, or you want to delete too many items. In this case you will get an exception.

Put content directly to the trash

Instead of deleting, you can put the content directly to the trash by placing it into a trash bag:

var book = Node.LoadNode(bookPath);

This method does not check the settings on the source container, only needs the Trash Bin to be enabled. It is possible that the move operation doesn't succeed (e.g. lack of permissions), in this case you receive an exception.

Delete content permanently

You can delete content permanently using the Delete API. This means you bypass the trash and will not be able to restore that content. The ForceDelete method of a Node creates a log entry and deletes the content permanently.


Restore content from the trash

Trashed items are in the folder /Root/Trash. All the items in the Trash Bin are Trash Bags that contain the actual deleted items as child content. If you found the item you want to restore (e.g. by a query), you can restore it to its original location or to another path:

var result1 = TrashBin.Restore(myTrashBag1);
var result2 = TrashBin.Restore(myTrashBag2, "/Root/MyWorkspace/DifferentFolder");

Restore errors

If an error occurs during the restore operation the result is a RestoreException that contains some information about the operation. The error result contains the type of the error in the form of an enumeration object of a RestoreResultType enum.

The selected destination folder or list does not exist in the repository.
A content with this name already exists in the destination folder. ContentPath property of the result contains the path and the suggested new name.
The target container does not allow this content type (e.g. in the meantime this content type was removed from the original containers Allowed Child Types list).
The user does not have enough permissions (e.g. See or Add) for the target container.
Restore caused an unknown error.

Overriding the default behavior

In some cases, you create your own Content Handler for your business entity and want to change the default delete mechanism. For example force the system to delete the content permanently, even if the trash is enabled.

You can change the default delete behavior by overriding the Delete method of the GenericContent class.

public class Book : GenericContent
  public override void Delete()
      //perform a custom operation
      //skip the trash and
      //delete the content permanently    

If you only want to prevent users deleting your custom content to the trash and always want to delete those content permanently you can do so by overiding the IsTrashable property of GenericContent:

public override bool IsTrashable
        return false;

Related links


There are no external references for this article.