I have been playing around with some custom workflow actions for SPD 2010, but I have an issue with one which works when running with the site collection admin user and not with a regular user with contribute.
The purpose of the action is to clear all permissions on an item and then in a later step add new groups/users with permissions.
But it fails, with the error code System.UnauthorizedAccessException:> Access is denied.
I use this method to elevate.
And here is most of the code:
try
{
using (SPSite site = new SPSite(__Context.Web.Site.ID, GetSystemToken(__Context.Web.Site)))
{
var list = __Context.Web.Lists[new Guid(__ListId)];
if (list == null) throw new ArgumentNullException("List");
var item = list.GetItemById(__ListItem);
item.BreakRoleInheritance(true);
// Remove current roles
SPRoleAssignmentCollection SPRoleAssColn = item.RoleAssignmnents;
for (int i = SPRoleAssColn.Count - 1; i >= 0; i--)
{
SPRoleAssColn.Remove(i);
}
using (DisabledItemEventsScope scope = new DisabledItemEventsScope())
{
item.Update();
}
}
}
catch(Exception ex)
{
//log
}
}