sharepoint2010 向用户组中添加用户

来源:互联网 发布:广西直销软件开发 编辑:程序博客网 时间:2024/04/29 22:53

    
   
            SPSecurity.RunWithElevatedPrivileges(delegate
            {
             
                using (SPSite spSite = new SPSite(Page.Request.Url.ToString()))
                {
                    using (SPWeb spWeb = spSite.OpenWeb())
                    {
                        try
                        {
                            
                            spWeb.AllowUnsafeUpdates = true;

                            SPUser spUser = spWeb.EnsureUser(“Text\mossadmin”);//根据登陆名称获取用户对象

                            if (spUser != null)
                            {


                                SPGroup spGroup = spWeb.Groups[“测试组”];//根据用户组名称获取用户组对象

                                if (spGroup != null)
                                    spGroup.AddUser(spUser);//将用户添加到用户组中
                            }
                        }
                        catch (Exception ex)
                        {
                           
                        }
                        finally
                        {
                            spWeb.AllowUnsafeUpdates = false;
                        }
                    }
                }

            });
     

原创粉丝点击