对文档库/列表单条目权限提升


      /// 对于还在使用继承权限的条目,重新权限,并通过copyRoleAss确定是否复制原来的权限

      public void ResetItemRight(string weburl,string listurl, int itemId, bool copyRoleAss)
        {
            spweb = spsite.OpenWeb(weburl);
            spweb.AllowUnsafeUpdates = true;

            if (weburl != null && listurl == null && itemId == 0)
            {
                if (!spweb.HasUniqueRoleAssignments)
                {
                    spweb.BreakRoleInheritance(copyRoleAss);
                    spweb.Update();
                }
            }
            else if (weburl != null && listurl != null && itemId == 0)
            {
                list = spweb.GetList(listurl);
                if (!list.HasUniqueRoleAssignments)
                {
                    list.BreakRoleInheritance(copyRoleAss);
                    list.Update();
                }
            }
            else if (weburl != null && listurl != null && itemId > 0)
            {
                list = spweb.GetList(listurl);
                SPListItem item = list.GetItemById(itemId);
                if (!item.HasUniqueRoleAssignments)
                {
                    item.BreakRoleInheritance(copyRoleAss);
                    item.Update();
                }
            }
        }

你可能感兴趣的:(权限)