Collaborations are used to share folders and files between users or groups. They also define what permissions a user has for a folder or file.
- Add a Collaboration
- Edit a Collaboration
- Remove a Collaboration
- Get a Collaboration's Information
- Get the Collaborations on a Folder
- Get the Collaborations on a File
- Get Pending Collaborations
A collaboration can be added for an existing user by calling
CollaborationsManager.AddCollaborationAsync(BoxCollaborationRequest collaborationRequest, IEnumerable<string> fields = null, bool? notify = null)
.
The Role
field of the collaborationRequest
parameter determines what permissions the collaborator will have on the
folder or file.
// collaborate folder 11111 with user 22222
BoxCollaborationRequest requestParams = new BoxCollaborationRequest()
{
Item = new BoxRequestEntity()
{
Type = BoxType.folder,
Id = "11111"
},
Role = "editor",
AccessibleBy = new BoxCollaborationUserRequest()
{
Type = BoxType.user,
Id = "22222"
}
};
BoxCollaboration collab = await client.CollaborationsManager.AddCollaborationAsync(requestParams);
Administrators can set the notify
parameter to false
to prevent the user who is being collaborated from receiving an
email notification about the collaboration.
If you want to collaborate a group, provide the type group and the group id.
// collaborate folder 11111 with group 333333
BoxCollaborationRequest requestParams = new BoxCollaborationRequest()
{
Item = new BoxRequestEntity()
{
Type = BoxType.folder,
Id = "11111"
},
Role = "editor",
AccessibleBy = new BoxCollaborationUserRequest()
{
Type = BoxType.group,
Id = "333333"
}
};
BoxCollaboration collab = await client.CollaborationsManager.AddCollaborationAsync(requestParams);
A collaboration can be edited by calling
CollaborationsManager.EditCollaborationAsync(BoxCollaborationRequest collaborationRequest, IEnumerable<string> fields = null)
with the fields to be updated. For example, to change the role of a collaboration:
BoxCollaborationRequest requestParams = new BoxCollaborationRequest()
{
Id = "12345",
Role = "viewer"
};
BoxCollaboration collab = await client.CollaborationsManager.EditCollaborationAsync(requestParams);
A collaboration can be removed by calling CollaborationsManager.RemoveCollaborationAsync(string id)
.
This will generally remove the user or group's access to the collaborated item.
await client.CollaborationsManager.RemoveCollaborationAsync(id: "12345");
To get information about a specific collaboration record, call
CollaborationsManager.GetCollaborationAsync(string id, IEnumerable<string> fields = null)
with the
ID of the collaboration.
BoxCollaboration collab = await client.CollaborationsManager.GetCollaborationAsync(id: "22222");
You can get all of the collaborations on a folder by calling
FoldersManager.GetCollaborationsAsync(string id, IEnumerable<string> fields = null)
with the ID of the folder.
string folderId = "11111";
BoxCollection<BoxCollaboration> collaborations = await client.FoldersManager
.GetCollaborationsAsync(folderId);
You can get the collection of collaborations on a file by calling
FilesManager.GetCollaborationsCollectionAsync(string id, string marker = null, int? limit = null, IEnumerable<string> fields = null, bool autoPaginate = false)
with the ID of the file.
string fileId = "98765";
BoxCollectionMarkerBasedV2<BoxCollaboration> collaborations = await client.FilesManager
.GetCollaborationsCollectionAsync(fileId);
A collection of all the user's pending collaborations can be retrieved with
CollaborationsManager.GetPendingCollaborationAsync(IEnumerable<string> fields = null)
.
BoxCollection<BoxCollaboration> pendingCollabs = await CollaborationsManager
.GetPendingCollaborationAsync();