Quantcast
Channel: SharePoint 2013 - Development and Programming forum
Viewing all articles
Browse latest Browse all 7589

Object reference error when try to break role inheritance for Tasks Lits in a sub site

$
0
0

hi,

i am trying to read the Tasks list in my sub site programmatically and trying to break the role  inheritance and apply contribute permissions to a set of  users.

but when i

private bool ApplyContriToTasklistforSubSite(string strBIFNodePathhURL, IList<SPUser> spuserCollecApprovers)
        {

          bool  isPermiApplied =false;
          try
            {
                SPSecurity.RunWithElevatedPrivileges(delegate()
                {
                    using (SPSite subNodeSite = new SPSite(strBIFNodePathhURL))
                    {
                        using (SPWeb subNodeWeb = subNodeSite.OpenWeb())
                        {
                            subNodeWeb.AllowUnsafeUpdates = true;

                            SPList splistTasksList = subNodeWeb.Lists.TryGetList("Tasks");

                            if (!splistTasksList.HasUniqueRoleAssignments)
                            splistTasksList.BreakRoleInheritance(true);

                            foreach(SPUser singleeUser in spuserCollecApprovers)
                            {
                                //SPGroup _singleWebCurentSelectedGroup = subNodeSiteforCTypeWeb.SiteGroups[currSelectedGroupNameforCType];
                                SPRoleAssignment _singleWebRoleAssignment = new SPRoleAssignment(singleeUser);
                                SPRoleDefinition _singleTaskRoleDefinition = subNodeWeb.RoleDefinitions["Contribute"];
                                _singleWebRoleAssignment.RoleDefinitionBindings.Add(_singleTaskRoleDefinition);
                                splistTasksList.RoleAssignments.Add(_singleWebRoleAssignment);
                            }
                            splistTasksList.Update();
                         subNodeWeb.AllowUnsafeUpdates = false;
                        }
                    }
                });
            }
            catch(SPException spekl) { }

            return isPermiApplied;
        }

Any idea what may be the reason for this.


Viewing all articles
Browse latest Browse all 7589

Trending Articles



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