Skip to content

Latest commit

 

History

History
128 lines (102 loc) · 4.52 KB

trash.md

File metadata and controls

128 lines (102 loc) · 4.52 KB

Trash

Under normal circumstances, when an item in Box is deleted, it is not actually erased immediately. Instead, it is moved to the Trash. The Trash allows you to recover files and folders that have been deleted. By default, items in the Trash will be purged after 30 days.

Get Trashed Items

To retrieve files and folders that have been moved to the Trash, call FoldersManager.GetTrashItemsAsync(int limit, int offset = 0, IEnumerable<string> fields = null, bool autoPaginate=false).

BoxCollection<BoxItem> trashedItems = await client.FoldersManager.GetTrashItemsAsync(limit: 100);

Get a Trashed File

Information about a file in the trash can be retrieved by calling the FilesManager.GetTrashedAsync(string id, IEnumerable<string> fields = null) method with the ID of the file in the trash.

BoxFile trashedFile = await client.FilesManager.GetTrashedAsync("11111");

Get a Trashed Folder

Information about a folder in the trash can be retrieved by calling the FoldersManager.GetTrashedFolderAsync(string id, IEnumerable<string> fields = null) method with the ID of the folder in the trash.

BoxFolder trashedFolder = await client.FoldersManager.GetTrashedFolderAsync("22222");

Purge a File from the Trash

Calling the FilesManager.PurgeTrashedAsync(string id) method will remove the file permanently from the user's trash.

await client.FilesManager.PurgeTrashedAsync("11111");

Purge a Folder from the Trash

Calling the FoldersManager.PurgeTrashedFolderAsync(string id) method will remove the folder permanently from the user's trash.

await client.FoldersManager.PurgeTrashedFolderAsync("22222");

Restore a File From Trash

Calling FilesManager.RestoreTrashedAsync(BoxFileRequest fileRequest, IEnumerable<string> fields = null) will restore an item from the user's trash. Default behavior is to restore the item to the folder it was in before it was moved to the trash. Options are available to handle possible failure cases: if an item with the same name already exists in folder's old location, the restored folder can be given an alternate name with the Name option. If the folder's old location no longer exists, it can be placed inside a new parent folder with the Parent.Id option.

var requestParams = new BoxFileRequest()
{
    Name = "Name in case of conflict",
    Parent = new BoxRequestEntity()
    {
        // File will be placed in this folder if original location no longer exists
        Id = "12345" 
    }
};
BoxFile restoredFile = await client.FilesManager.RestoreTrashedAsync(requestParams);

Restore a Folder from Trash

A folder can be restored from the trash with the FoldersManager.RestoreTrashedFolderAsync(BoxFolderRequest folderRequest, IEnumerable<string> fields = null) method. Default behavior is to restore the item to the folder it was in before it was moved to the trash. Options are available to handle possible failure cases: if an item with the same name already exists in folder's old location, the restored folder can be given an alternate name with the Name option. If the folder's old location no longer exists, it can be placed inside a new parent folder with the Parent.Id option.

var requestParams = new BoxFolderRequest()
{
    Name = "Name in case of conflict",
    Parent = new BoxRequestEntity()
    {
        // Folder will be placed in this parent folder if original location no longer exists
        Id = "12345" 
    }
};
BoxFolder restoredFolder = await client.FoldersManager.RestoreTrashedFolderAsync(requestParams);