1

SharePoint calendar events needs to display only for particular users only. I have added a People and group column in Calendar list.. and get the users from that column.. after that i don't know how to change the permission for those users? Those users only can view the events. Can i set the permission in code behind. please help.

1

Are you talking about strict permissions or trimming? If it is really important that only the specified users can see the calendar items then you will need a workflow or similar to set unique permissions on the item based on the column - I know you can do this with Nintex workflow but I have not tried with SPD workflow.

Trimming is where you filter a view to only show items to the selected users. Apply a filter to the view where your new People Column contains [Me] - [Me] is a special filter which will use the current user. However, if a user goes directly to the list or a different unfiltered view of the list they will still see the item.

2
  • Thanks for your reply.. i get some idea from your reply. Here let me explain requirement.. 1. First i create a column named users in Calendar list with type People and Group.. 2. I going to create a new event and add multiple users in 'users' column and save the event. 3. We have to display the event in calendar for particular users only. so can you give some more possible ways.. i could achieve my requirements easily.. Thank you. – Cegone Dec 29 '13 at 15:20
  • Applying permission control is going to be more complex than trimming so if that is acceptable it would be my suggested approach. – Dave Paylor Dec 29 '13 at 21:45
1
public override void ItemAdded(SPItemEventProperties properties)
        {
            SPListItem fromListItems = properties.ListItem;

            try
            {               
                properties.ListItem.BreakRoleInheritance(false);
                UpdateListItems(properties);

                base.ItemAdded(properties);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

 private void UpdateListItems(SPItemEventProperties properties)
        {

            using (currentWeb = properties.OpenWeb())
            {
                try
                {
                    SPUser spLookUpUser = null;
                    SPFieldLookupValue fieldLookupValue = new SPFieldLookupValue(properties.ListItem["user"].ToString());
                    string lookupValues = fieldLookupValue.LookupValue;
                    SPFieldLookupValueCollection fieldLoodUpValueCollection = new SPFieldLookupValueCollection(properties.ListItem["user"].ToString());

                    foreach (SPFieldLookupValue lookupValue in fieldLoodUpValueCollection)
                    {
                        string lookUpUser = lookupValue.LookupValue;
                        spLookUpUser = currentWeb.EnsureUser(lookUpUser);
                        SPPrincipal assignee = (SPPrincipal)spLookUpUser;
                        GrantPermission(properties.ListItem, currentWeb, SPRoleType.Reader, assignee);


                    }

                    properties.ListItem.SystemUpdate();
                }
                catch (Exception ex)
                {
                    throw ex;
                }
            }
        }



  private static void GrantPermission(SPListItem CurrentListItem, SPWeb oSPWeb, SPRoleType SPRoleType, SPPrincipal SPPrincipal)
        {
            try
            {                   
                SPRoleDefinition oSPRoleDefinition = oSPWeb.RoleDefinitions.GetByType(SPRoleType);                   
                SPRoleAssignment oSPRoleAssignment = new SPRoleAssignment(SPPrincipal);                   
                oSPRoleAssignment.RoleDefinitionBindings.Add(oSPRoleDefinition);                   
                CurrentListItem.RoleAssignments.Add(oSPRoleAssignment);                   
                CurrentListItem.Update();
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
1
  • Thanks for all of your helps.. any more suggestion.. plz give me :) – Cegone Jan 2 '14 at 11:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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