Skip to content

Latest commit

 

History

History
60 lines (46 loc) · 2.11 KB

collections.md

File metadata and controls

60 lines (46 loc) · 2.11 KB

Collections

Collections are used to store a custom user-defined set of items that may not all be in the same folder.

Get a User's Collections

Get a list of all collections the user has defined by calling CollectionsManager.GetCollectionsAsync(). A user always has a default collection called "Favorites" which they can add items to.

BoxCollection<BoxCollectionItem> collections = await client.CollectionsManager.GetCollectionsAsync();

Get the Items in a Collection

Get a list of the items in a collection by passing the ID of the collection to CollectionsManager.GetCollectionItemsAsync(string collectionId, int limit = 100, int offset = 0, IEnumerable<string> fields = null, bool autoPaginate = false).

BoxCollection<BoxItem> items = await client.CollectionsManager.GetCollectionItemsAsync(id: "11111");

Set an Item's Collections

You can set the collections an item belongs to by calling CollectionsManager.CreateOrDeleteCollectionsForFolderAsync(string folderId, BoxCollectionsRequest collectionsRequest) or CollectionsManager.CreateOrDeleteCollectionsForFileAsync(string fileId, BoxCollectionsRequest collectionsRequest).

// Put file 11111 into collection 22222
BoxCollectionsRequest requestParams = new BoxCollectionsRequest()
{
    Collections = new List<BoxRequestEntity>()
    {
        new BoxRequestEntity()
        {
            Id = "22222"
        }
    };
};
BoxFile file = await client.CollectionsManager.CreateOrDeleteCollectionsForFileAsync(fileId: "11111", requestParams);