Folder objects represent a folder from a user's account. They can be used to iterate through a folder's contents, collaborate a folder with another user or group, and perform other common folder operations (move, copy, delete, etc.).
- Get a Folder's Items
- Get a Folder's Information
- Update a Folder's Information
- Create a Folder
- Copy a Folder
- Delete a Folder
- Create or update a Shared Link
- Create a Folder Lock
- Get Folder Locks
- Delete a Folder Lock
Folder items can be retrieved by calling the
FoldersManager.GetFolderItemsMarkerBasedAsync(string id, int limit string marker = null, IEnumerable<string> fields = null, bool autoPaginate = false, string sort = null, BoxSortDirection? direction = null, string sharedLink = null, string sharedLinkPassword = null)
method. Use the fields
option to specify the desired fields.
Requesting information for only the fields you need can improve performance by reducing the size of the network response.
Following method supports marker-based pagination.
BoxCollection<BoxItem> folderItems = await client.FoldersManager.GetFolderItemsMarkerBasedAsync("11111", 100);
Alternatively you can use method with offset-based pagination.
BoxCollection<BoxItem> folderItems = await client.FoldersManager.GetFolderItemsAsync("11111", 100, offset: 10);
Folder information can be retrieved by calling
FoldersManager.GetInformationAsync(string id, IEnumerable<string> fields = null)
with the ID of the folder.
BoxFolder folder = await client.FoldersManager.GetInformationAsync("11111");
Updating a folder's information is done by calling the
FoldersManager.UpdateInformationAsync(BoxFolderRequest folderRequest, IEnumerable<string> fields = null, string etag = null)
method.
var requestParams = new BoxFolderRequest()
{
Id = "11111",
Name = "My Documents (2017)"
};
BoxFolder updatedFolder = await client.FoldersManager.UpdateInformationAsync(requestParams);
Create a subfolder inside of another folder by calling
FoldersManager.CreateAsync(BoxFolderRequest folderRequest, IEnumerable<string> fields = null)
.
// Create a new folder in the user's root folder
var folderParams = new BoxFolderRequest()
{
Name = "New folder",
Parent = new BoxRequestEntity()
{
Id = "0"
}
};
BoxFolder folder = await client.FoldersManager.CreateAsync(folderParams);
To copy a folder from its current location into a different folder, call
FoldersManager.CopyAsync(BoxFolderRequest folderRequest, IEnumerable<string> fields = null)
.
// Copy folder 11111 into folder 22222
var requestParams = new BoxFolderRequest()
{
Id = "11111",
Parent = new BoxRequestEntity()
{
Id = "22222"
}
};
BoxFolder folderCopy = await client.FoldersManager.CopyAsync(requestParams);
A folder can be deleted by calling FoldersManager.DeleteAsync(string id, bool recursive = false, string etag = null)
with the ID of the folder to delete. By default, the folder will only be deleted if it is empty; to delete the
folder and all of its contents, set the optional recursive
parameter to true
.
await client.FoldersManager.DeleteAsync("11111", recursive: true);
You can create or update a shared link for a folder by calling
FoldersManager.CreateSharedLinkAsync(string id, BoxSharedLinkRequest sharedLinkRequest, IEnumerable<string> fields = null)
with the ID of the folder and the shared link parameters.
var sharedLinkParams = new BoxSharedLinkRequest()
{
Access = BoxSharedLinkAccessType.open
};
BoxFolder folder = await client.FoldersManager.CreateSharedLinkAsync("11111", sharedLinkParams);
string sharedLinkUrl = folder.SharedLink.Url;
To lock a folder, call
FoldersManager.CreateLockAsync(string id)
with the ID of the folder. This prevents the folder from being moved and/or deleted.
BoxFolderLock folderLock = await _foldersManager.CreateLockAsync("11111");
To retrieve a list of the locks on a folder, call
FoldersManager.GetLocksAsync(string id, bool autoPaginate
with the ID of the folder. Currently only one lock can exist per folder. Folder locks define access restrictions placed by folder owners to prevent specific folders from being moved or deleted.
BoxCollection<BoxFolderLock> folderLock = await _foldersManager.GetLocksAsync("11111");
string id = folderLock.Entries[0].Id;
To remove a folder lock, call
FoldersManger.DeleteLockAsync(string id)
with the ID of the folder lock.
await _foldersManager.DeleteLockAsync("11111");