First we get the category, and the AccessControlEntries as a list.
CategoryData category = client.Read("tcm:3-804-512", new ReadOptions());
List<AccessControlEntryData> accessControlEntries =
category.AccessControlList.AccessControlEntries.ToList();
Next we create a new AccessControlEntryData instance representing "Everyone", and assign it Read permissions.
AcessControlEntryData access = new AccessControlEntryData();
access.Trustee = new LinkToTrusteeData { IdRef = "tcm:0-1-65568" };
access.AllowedPermissions = Permissions.Read;
Next we add the new access entry to our List, and then set the List as an array back to the category's AccessControlList.AccessControlEntries property.
accessControlEntries.Add(access);
category.AccessControlList.AccessControlEntries = accessControlEntries.ToArray();
And of course finally save. :)
client.Save(category, null);
Hope that helps!
Update:
In the above example, if Everyone is already in the AccessControlEntries, your AllowedPermissions attribute will be added to the Permission flags. It does not replace the existing value, which could cause some confusion depending on what you are trying to set and whether or not it already exists. It would probably be better to check first to see if Everyone was already a part of the AccessControlEntries if you wish to fully replace the existing value.
List<AccessControlEntryData> accessControlEntries
= category.AccessControlList.AccessControlEntries.ToList();
AccessControlEntryData access = accessControlEntries
.Where(a => a.Trustee.Title.Equals("Everyone"))
.FirstOrDefault();
if (access == null)
{
access = new AccessControlEntryData();
access.Trustee = new LinkToTrusteeData { IdRef = "tcm:0-1-65568" };
accessControlEntries.Add(access);
}
access.AllowedPermissions = Permissions.Read;
category.AccessControlList.AccessControlEntries = accessControlEntries.ToArray();
If you wish to remove an entry, you can actually set the permissions to None;
access.AllowedPermissions = Permissions.None;
Also for anyone reading this who hasn't worked with Bit Flags, you can set multiple permissions like this:
access.AllowedPermissions = Permissions.Read | Permissions.Write;