• sharepoint 2013 文档库eventhandle权限控制


    记录一下如何在sharepoint server 2013文档库中,使用eventhandle控制文档库document library的条目item权限。

           ///<summary>

            ///已添加项.

            ///</summary>

            public override void ItemAdded(SPItemEventProperties properties)

            {

                base.ItemAdded(properties);

                SPSecurity.RunWithElevatedPrivileges(delegate()

                {

                    if(properties.ListTitle =="共享文档1")

                    {

                        SPSite site =newSPSite(properties.SiteId);

                        SPWeb web =site.OpenWeb();

                        web.AllowUnsafeUpdates = true;

                        SPList list =web.Lists[properties.ListId];

                        SPFile file =list.GetItemById(properties.ListItemId).File;

                        SPListItem item = file.Item;

                        //权限断开,并且移除掉其它权限

                        if(!item.HasUniqueRoleAssignments)

                        {

                           item.BreakRoleInheritance(false);

                        }

                        //添加用户权限

                        SPUser CurrentUser =web.EnsureUser(properties.UserLoginName);

                        SPRoleAssignment MyRoleAssignment =newSPRoleAssignment(CurrentUser);

                       MyRoleAssignment.RoleDefinitionBindings.Add(web.RoleDefinitions.GetByType(SPRoleType.WebDesigner));

                       item.RoleAssignments.Add(MyRoleAssignment);

     

                        CurrentUser =web.EnsureUser("kw\cxx");

                        MyRoleAssignment = newSPRoleAssignment(CurrentUser);

                       MyRoleAssignment.RoleDefinitionBindings.Add(web.RoleDefinitions.GetByType(SPRoleType.WebDesigner));

                       item.RoleAssignments.Add(MyRoleAssignment);

                        item.Update();

                    }

                });

            }

  • 相关阅读:
    [置顶] Spring的自动装配
    BZOJ2831(小强的金字塔系列问题--区域整点数求法)
    国际跆拳道联盟
    Linux如何查找某个时间点后生成的空文件
    ORACLE中关于外键缺少索引的探讨和总结
    ORA-12514, TNS:listener does not currently know of service requested in connect descriptor案例2
    SQL Server 2005 sp_send_dbmail出现Internal error at FormatRowset (Reason: Not enough storage is available to complete this operation)
    SQL Server数据库邮件发送异常案例
    MySQL二进制日志总结
    OSWatcher使用过程中小问题解决方法
  • 原文地址:https://www.cnblogs.com/jiangu66/p/3184523.html
Copyright © 2020-2023  润新知