Click or drag to resize

Example 3: Add permissions for a group of users to access a file

This example allows access to a document for a group of users. It assumes a group and a workspace exist, the latter with a single document, and group ("mygroup") exists; these are described in the preceding example.

Get list of documents in a Workspace
C#
Resource.Workspaces workspaces = apiSession.GetWorkspacesResource();

// Create a json object for the document search, and accept its defaults.
// Adjust if needed.
ListDocumentsVdrJson listDocumentsJson = new ListDocumentsVdrJson();

// Make the call to get the list of documents
PagingItemListJson<BaseJson> documentList =
    workspaces.ListDocumentsV30(roomId, listDocumentsJson);
Create the json object for the permissions

Default to true value for all permission. Set the group name and EntityType.GROUP as well. Note the nested json objects that are created and then set on other, enclosing json objects.

C#
PermittedEntityFromUserJson groupPermission = new PermittedEntityFromUserJson
{
    Address = groupName,
    EntityType = EntityType.GROUP

};

List<PermittedEntityFromUserJson> permissionsList =
    new List<PermittedEntityFromUserJson>
    {
        groupPermission
    };

// Adjust permissions as needed
PermissionSetJson permissionSet = new PermissionSetJson
{
    DownloadOriginal = YesNoDefault.YES,
    DownloadControlled = YesNoDefault.YES,
    Copy = YesNoDefault.YES,
    Edit = YesNoDefault.YES,
    Print = YesNoDefault.YES,
    ProgrammaticAccess = YesNoDefault.YES,
    Spotlight = YesNoDefault.YES,
    Watermark = YesNoDefault.YES
};

HashSet<string> documentGuids = new HashSet<string>
{
    myDoc.Guid
};

VdrAddPermissionsJson permissionsJson = new VdrAddPermissionsJson
{
    PermittedEntities = permissionsList,
    PermissionSet = permissionSet,
    DocumentGuids = documentGuids
};
Add permissions to the group

Set the document GUID from the returned document list and make the call to set the permissions. A BulkOperationResultJson is returned, which has information on the success or failure(with errors encountered) for each document in the list(which in this case was just 1).

C#
// Add permissions
BulkOperationResultJson result =
    workspaces.AddPermissionsV30(roomId, permissionsJson);