Quantcast
Channel: SharePoint 2010 - Development and Programming forum
Viewing all articles
Browse latest Browse all 11571

First deny permissions to All users for the list item and grant only one user to access the item

$
0
0

in my event receiver i have to write the below functionality:

 Deny permission for all but one user .

i tried below : but it throws an error  on this line :

                                                        SPRoleDefinition biffroledefi = CurrentWeb.RoleDefinitions[SPRoleType.None];

how can i deny access  for the currentlistitem to the all users in my  site collection and then i want to add only one person to access this listitem. 

CurrentWeb.RoleDefinitions[SPRoleType.None];

try
            {
                string currentuserIdd = properties.CurrentUserId.ToString();

...............

...........

CurrentWeb.AllowUnsafeUpdates = true;

                                CurrentListItem.BreakRoleInheritance(false);

                                
                                   SPRoleAssignment AllBIFRoleassignment = new SPRoleAssignment(myusersGroup);
                                                        SPRoleDefinition biffroledefi = CurrentWeb.RoleDefinitions[SPRoleType.None);
                                                        AllBIFRoleassignment.RoleDefinitionBindings.Add(biffroledefi);
                                                        CurrentListItem.RoleAssignments.Add(AllBIFRoleassignment);

                                                        // added on 7 pm 04-june-2014

                                                        SPRoleAssignment mroleAssignmentforCurrUser = new SPRoleAssignment(currUser);
                                                        SPRoleDefinition mroleDefinitionforCurrUser = CurrentWeb.RoleDefinitions["Full Control"];
                                                        mroleAssignmentforCurrUser.RoleDefinitionBindings.Add(mroleDefinitionforCurrUser);
                                                        CurrentListItem.RoleAssignments.Add(mroleAssignmentforCurrUser);

                                                        this.EventFiringEnabled = false;

                                                        CurrentListItem["Author"] = currentuserIdd;
                                                        CurrentListItem.Update();

                                                        CurrentListItem["Editor"] = currentuserIdd;
                                                        CurrentListItem.Update();
                                                        this.EventFiringEnabled = true;
                                                        CurrentWeb.AllowUnsafeUpdates = false;



Viewing all articles
Browse latest Browse all 11571

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>