Click or drag to resize

Example 7: Change file permissions

This case shows how permissions can be changed for a document in a Workspace. The document is selected by the group that has access rights to it. In this example, the permissions to be set are: edit, print, spotlight, watermark - No. All other permissions will remain unchanged.

This case assumes the guid for the document is known; if not, a list of documents can be retrieved as shown in Example 3, the desired document selected by name, and the GUID retrieved from it.

C#
// Create the json that indicates the group that has permissions to the document
PermittedEntityFromUserJson groupPermission = new PermittedEntityFromUserJson
{
    Address = groupName,
    EntityType = EntityType.GROUP
};

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

// Add the document GUID
HashSet<string> documentGuids = new HashSet<string>
{
    myDoc.Guid
};

// Create the json for the permissions and set them to NO
PermissionSetJson permissionSet = new PermissionSetJson
{
    DownloadOriginal = YesNoDefault.NO,
    DownloadControlled = YesNoDefault.NO,
    Edit = YesNoDefault.NO,
    Print = YesNoDefault.NO,
    Spotlight = YesNoDefault.NO,
    Watermark = YesNoDefault.NO,
    Copy = YesNoDefault.NO,
    ProgrammaticAccess = YesNoDefault.NO,
};

VdrEditPermissionsJson editPermissionsJson = new VdrEditPermissionsJson
{
    PermittedEntities = permissionsList,
    DocumentGuids = documentGuids,
    PermissionSet = permissionSet
};

// Make the call and get a BulkOperationResultJson back
BulkOperationResultJson result =
    workspaces.EditPermissionsV30(roomId, editPermissionsJson);