zoukankan      html  css  js  c++  java
  • 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();

                    }

                });

            }

  • 相关阅读:
    电路开发软件积累
    .NET移动开发环境搭建
    Microsoft SQL Server Express各版本对比
    .NET IL指令速查表
    C#访问加密的SQLite数据库
    C#中时间计算方法汇总
    最佳C/C++编辑器 source insight3
    常用PHP框架收集
    CSS 中文字体的英文名称 (simhei, simsun) 宋体 微软雅黑等
    Windows下Java JDK8配置环境变量
  • 原文地址:https://www.cnblogs.com/jiangu66/p/3184523.html
Copyright © 2011-2022 走看看