1

I'm on SharePoint 2013 and I'm using C#. I'm working with the ItemAdding event receiver.
Using SPItemEventProperties I can get the user login name associated with the file I'm adding, with this kind of format: i:0#.w|domain\\example (UserLoginName property).
I also have a SPListItem object and I want to check if the user has Full Control permission level on this item.
I can't find a working solution, could someone help me, please?
I tried working with SPBasePermissions but FullMask seems not equivalent to Full Control.
Thanks in advance!

1 Answer 1

0

Try the below code to check if the current user has Full Control Permission

if (SPContext.Current.Web.AllRolesForCurrentUser.Contains(SPContext.Current.Web.RoleDefinitions["Full Control"]))
{
//do something
}

If it's not working try the below code:

using (SPSite site = new SPSite(strSite))
{
using (SPWeb web = site.OpenWeb())
{  
try
{
SPUser user = web.Users["current user"];
SPRoleAssignment currentUserRole = web.RoleAssignments.GetAssignmentByPrincipal(user);
foreach (SPRoleDefinition role in currentUserRole.RoleDefinitionBindings)
{
if (role.Name.ToString() == "Full Control")
{
 // has full control
}
}
}
 catch (Exception)
{
throw;
}
}
}

For more details check How to find permission level for specific user using visual studio?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.