Frage

I would like to list the permission from every Outlook folder. I can add permissions but my code delete all old permissions and set the new permission.

This is my code to add permission:

private void updateFolderPermission(Folder folder, String mail, int per)
{
  UserId delegateUser = new UserId(mail);
  FolderPermission permission = new FolderPermission(delegateUser, FolderPermissionLevel.None);

  switch (per)
  {
    case 0:
      {
        permission = new FolderPermission(delegateUser, FolderPermissionLevel.Owner);
        break;
      }
    case 1:
      {
        permission = new FolderPermission(delegateUser, FolderPermissionLevel.PublishingEditor);
        break;
      }
    case 2:
      {
        permission = new FolderPermission(delegateUser, FolderPermissionLevel.Editor);
        break;
      }
    case 3:
      {
        permission = new FolderPermission(delegateUser, FolderPermissionLevel.PublishingAuthor);
        break;
      }
    case 4:
      {
        permission = new FolderPermission(delegateUser, FolderPermissionLevel.Author);
        break;
      }
    case 5:
      {
        permission = new FolderPermission(delegateUser, FolderPermissionLevel.NoneditingAuthor);
        break;
      }
    case 6:
      {
        permission = new FolderPermission(delegateUser, FolderPermissionLevel.Reviewer);
        break;
      }
    case 7:
      {
        permission = new FolderPermission(delegateUser, FolderPermissionLevel.Contributor);
        break;
      }
    case 8:
      {
        permission = new FolderPermission(delegateUser, FolderPermissionLevel.None);
        break;
      }
  }      
  folder.Permissions.Add(permission);
  folder.Update();
}

I had debug the code but the function _permissions_ shows me _count = 0_.

My question is now: - How can I add a permission to an existing permissionSet? - How can I list all permissions on this folder?

War es hilfreich?

Lösung

TuVi-

To list the permissions on the a folder, create a property set that includes FolderSchema.Permissions, then bind to the Folder with that property set:

PropertySet propSet = new PropertySet(BasePropertySet.FirstClassProperties, FolderSchema.Permissions);
Folder folder = Folder.Bind(service, folderid, propSet);

To add permissions to an existing permission set, the way I got it to work (and what was recommended here: here: http://social.msdn.microsoft.com/Forums/exchange/en-US/96da6ca5-9756-4f15-a57c-6a2962820727/ews-get-read-folder-permissions?forum=exchangesvrdevelopment) is to remove the permissions currently associated with the user, then add the new permission back in. If you don't do this, and you just try to add the new perms, you'll get an error about a duplicating the user id in the DACL. So the following code removes the old perms and adds new perms (PublishingAuthor).

       PropertySet propSet = new PropertySet(BasePropertySet.FirstClassProperties, FolderSchema.Permissions);
       Folder folder = Folder.Bind(service, folderid, propSet);

       if (folder.Permissions.Count != 0)
        {
            for (int t = 0; t < folder.Permissions.Count; t++)
            {
                // Find any permissions associated with the specified user and remove them from the DACL
                if (folder.Permissions[t].UserId.DisplayName != null || folder.Permissions[t].UserId.PrimarySmtpAddress != null)
                {
                    folder.Permissions.Remove(folder.Permissions[t]);
                }
            }
        }

        //Now add the new permissions to the DACL 
        FolderPermission fldperm = new FolderPermission("sadied@contoso.onmicrosoft.com", FolderPermissionLevel.PublishingAuthor);
        folder.Permissions.Add(fldperm);
        folder.Update(); 

Hope that helps! And if it does, please don't forget to mark this answer as accepted.

Andere Tipps

private void updateFolderPermission(Folder folder, String mail, int per)
{
  UserId delegateUser = new UserId(mail);
  FolderPermission permission = new FolderPermission(delegateUser, FolderPermissionLevel.None);

  switch (per)
  {
    case 0:
      {
        permission = new FolderPermission(delegateUser, FolderPermissionLevel.Owner);
        break;
      }
    case 1:
      {
        permission = new FolderPermission(delegateUser, FolderPermissionLevel.PublishingEditor);
        break;
      }
    case 2:
      {
        permission = new FolderPermission(delegateUser, FolderPermissionLevel.Editor);
        break;
      }
    case 3:
      {
        permission = new FolderPermission(delegateUser, FolderPermissionLevel.PublishingAuthor);
        break;
      }
    case 4:
      {
        permission = new FolderPermission(delegateUser, FolderPermissionLevel.Author);
        break;
      }
    case 5:
      {
        permission = new FolderPermission(delegateUser, FolderPermissionLevel.NoneditingAuthor);
        break;
      }
    case 6:
      {
        permission = new FolderPermission(delegateUser, FolderPermissionLevel.Reviewer);
        break;
      }
    case 7:
      {
        permission = new FolderPermission(delegateUser, FolderPermissionLevel.Contributor);
        break;
      }
    case 8:
      {
        permission = new FolderPermission(delegateUser, FolderPermissionLevel.None);
        break;
      }
  }

  Folder myFolder = Folder.Bind(this.service, folder.Id);
  FolderPermissionCollection fpc = myFolder.Permissions;

  folder.Permissions.Add(permission);

  foreach (FolderPermission fp in fpc)
  {
    if (fp.UserId.DisplayName != null)
    {
      //folder.Permissions.Add(oldPer);
      if (fp.UserId.PrimarySmtpAddress != mail)
      {
        oldUser = new UserId(fp.UserId.PrimarySmtpAddress);
        oldPer = new FolderPermission(oldUser, fp.PermissionLevel);

        folder.Permissions.Add(oldPer);
      }
    }
  }

  try
  {
    folder.Update();
  }
  catch (Exception ex)
  {
    Console.WriteLine(ex.ToString());
  }
}
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top