Create/Set Folder Level Permissions with Exchange Web Services (Exchange Server 2007 SP1)


                    Le Café Central de
Deva              

                                 
                                 ..... Deva blogs!!




 

 

Create/Set Folder Level Permissions with Exchange Web Services (Exchange Server 2007 SP1)

  • Comments 1

Folder-level permissions work with other Exchange Web Services (Exchange Server 2007 SP1) 

Folder-level permissions work with other Exchange Web Services operations in the following ways:

  • The GetFolder operation will return the permissions that are set on the folder when the AllProperties shape is specified.
  • The SyncFolderHierarchy operation synchronizes PermissionSets.
  • The UpdateFolder operation will fail if multiple Permission entries are provided for the same user. The UpdateFolder response will return the ErrorDuplicateUserIdsSpecified response code.
  • The AppendToFolderField option of the UpdateFolder operation will append a permission entry for a user if the user does not already have a permission entry in the access control list (ACL) of the folder. If the user that is specified already has a permission entry, an ErrorUserAlreadyExists response code will be returned.
  • The SetFolderField option of the UpdateFolder operation will overwrite all the permission settings on the folder. The client cannot change the permissions for each user.
  • The DeleteFolderField option of the UpdateFolder operation will delete all the permission settings on the folder. 

Sample Code:

The following code example shows you how to set folder-level permissions when a folder is created. The authenticated user grants user3 the Editor permission level on a new folder named NewFolderWithPermissionsSet that is created in the Inbox default folder. 

static void CreateFolderLevelPermissions()
{
    // Set the version, credentials, and the Client Access server on ExchangeServiceBinding.
    ExchangeServiceBinding esb = new ExchangeServiceBinding();
    esb.RequestServerVersionValue = new RequestServerVersion();
    esb.RequestServerVersionValue.Version = ExchangeVersionType.Exchange2007_SP1;
    esb.Credentials = new NetworkCredential("username", "password", "domain");
    esb.Url = "https://CAS.example.com/ews/exchange.asmx";

    // Create user identifier.
    UserIdType user = new UserIdType();
    user.PrimarySmtpAddress = "user3@example.com.com";

    // Set the folder permission level to Editor.
    PermissionSetType permissionSet = new PermissionSetType();
    permissionSet.Permissions = new PermissionType[] { new PermissionType() };
    //permissionSet.Permissions[0] = new PermissionType();
    permissionSet.Permissions[0].PermissionLevel = PermissionLevelType.Editor;
    permissionSet.Permissions[0].UserId = user;

    FolderType folder = new FolderType();
    folder.DisplayName = "NewFolderWithPermissionsSet";
    folder.PermissionSet = permissionSet;

    // Specify the target folder.
    DistinguishedFolderIdType inbox = new DistinguishedFolderIdType();
    inbox.Id = DistinguishedFolderIdNameType.inbox;
    TargetFolderIdType targetFolder = new TargetFolderIdType();
    targetFolder.Item = inbox;

    CreateFolderType request = new CreateFolderType();
    request.Folders = new FolderType[] { folder };
    request.ParentFolderId = targetFolder;

    try
    {
        // Send the request and get the response.
        CreateFolderResponseType response = esb.CreateFolder(request);

        // Get the response messages.
        ResponseMessageType[] rmta = response.ResponseMessages.Items;

        // Cast to appropriate response message type.
        if (((FolderInfoResponseMessageType)rmta[0]).ResponseClass == ResponseClassType.Success)
        {
            // Continue.
        }
       
    }

    catch
    {
        // Handle errors.
    }
}

For more information refer this article

Blog - Post Feedback Form(CAPTCHA)
Leave a Comment
  • Post