• Sharepoint 在网站中创建用户组并添加权限


            /// <summary>
            /// 在当前网站中创建用户组
             /// </summary>
            /// <param name="strGroupName">用户组名称</param>
            /// <param name="strPermission">用户组权限</param>
            /// <param name="strDescription">用户组描述</param>
            private void CreateGroup(string strGroupName, string strPermission, string strDescription)
            {
                SPSecurity.RunWithElevatedPrivileges(delegate() {
                    try
                    {
                        using (SPSite site = SPContext.Current.Site)
                        {
                            SPGroupCollection groups = site.RootWeb.SiteGroups;
                            SPMember spMember = site.RootWeb.CurrentUser;
                            SPUser spUser = site.RootWeb.CurrentUser;
    
                            groups.Add(strGroupName,spMember,spUser, strPermission);
                            
                            AddPermission(site.RootWeb, strGroupName, strPermission);
                        }
                    }
                    catch (Exception ex) { throw ex; }
                });
            }
    
            /// <summary>
            /// 给指定用户组添加权限
             /// </summary>
            /// <param name="spWeb">网站url</param>
            /// <param name="spGroupName">用户组名称</param>
            /// <param name="strPermission">权限名称</param>
            private void AddPermission(SPWeb spWeb,string spGroupName, string strPermission)
            {
                try
                {
                    spWeb.AllowUnsafeUpdates = true;
                    SPRoleAssignment roleAssignment = new SPRoleAssignment(spWeb.SiteGroups[spGroupName]);
                    roleAssignment.RoleDefinitionBindings.Add(spWeb.RoleDefinitions[strPermission]);
    
                    if (!spWeb.HasUniqueRoleAssignments)
                    {
                        spWeb.BreakRoleInheritance(false);
                    }
                    spWeb.RoleAssignments.Add(roleAssignment);
                    spWeb.Update();
                }
                catch (Exception ex) { throw ex; }
                finally { spWeb.AllowUnsafeUpdates = false; }
            }
  • 相关阅读:
    全景拼接
    krpano之字幕添加
    UML之时序图
    krpano之语音介绍
    小工具之录音(文字转语音)
    动态生成按钮的点击事件绑定
    登录之简单验证码
    登录之md5加密
    redis与mysql数据同步
    Sql Server 主从数据库配置
  • 原文地址:https://www.cnblogs.com/qixing_gan/p/2771892.html
Copyright © 2020-2023  润新知