SharePoint中低权限用户通过提升权限创建用户组

/// <summary>
        /// 提升权限创建用户组
        /// </summary>
        /// <param name="groupname">用户组的名字</param>
        public void CreateGroup(string groupname)
        {
            SPSecurity.RunWithElevatedPrivileges(delegate()
            {
                try
                {
                    using (SPSite mySite = new SPSite(SPContext.Current.Site.ID))
                    {
                        using (SPWeb myWeb = mySite.OpenWeb())
                        {
                            myWeb.AllowUnsafeUpdates = true;
                            myWeb.SiteGroups.Add(groupname, myWeb.CurrentUser, null, "");
                            myWeb.AllowUnsafeUpdates = false;
                        }
                    }
                }
                catch (Exception ex)
                {
                    //throw custom exception

 

posted @ 2013-11-13 11:36  TwinStudio  阅读(210)  评论(0编辑  收藏  举报